Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IModel.IsClosed set to false after dispose #1086

Closed
eduard-bystrov opened this issue Sep 17, 2021 · 1 comment · Fixed by #1450
Closed

IModel.IsClosed set to false after dispose #1086

eduard-bystrov opened this issue Sep 17, 2021 · 1 comment · Fixed by #1450
Assignees
Milestone

Comments

@eduard-bystrov
Copy link

Example:

public static async Task Main(string[] args)
{
	var factory = new ConnectionFactory() { HostName = "localhost" };
	using var connection = factory.CreateConnection();

	var channel = connection.CreateModel();

	channel.QueueDeclare(queue: "task_queue", exclusive: false, autoDelete: false);

	var message = "Hello";
	var body = Encoding.UTF8.GetBytes(message);

	// restart rmq service here
	while (true)
	{
		try
		{
			var properties = channel.CreateBasicProperties();
			channel.BasicPublish(exchange: "", routingKey: "task_queue", basicProperties: properties, body: body);
			Console.WriteLine(" [x] Sent {0}", message);
		}
		catch (Exception ex)
		{
			Console.WriteLine(ex.ToString());
			break;
		}

		await Task.Delay(1000);
	}

	Console.WriteLine($"IsClosed:{channel.IsClosed}");
	channel.Dispose();
	Console.WriteLine($"IsClosed:{channel.IsClosed}");
}

// [x] Sent Hello
//  ...
// RabbitMQ.Client.Exceptions.AlreadyClosedException: Already closed: The AMQP operation was interrupted: AMQP close-reason, initiated by Peer, code=320, text='CONNECTION_FORCED - broker forced connection closure // // with reason 'shutdown'', classId=0, methodId=0
//    at RabbitMQ.Client.Impl.SessionBase.Transmit(OutgoingCommand& cmd)
//    at RabbitMQ.Client.Impl.ModelBase.ModelSend(MethodBase method, ContentHeaderBase header, ReadOnlyMemory`1 body)
//    at RabbitMQ.Client.Framing.Impl.Model._Private_BasicPublish(String exchange, String routingKey, Boolean mandatory, IBasicProperties basicProperties, ReadOnlyMemory`1 body)
//    at RabbitMQ.Client.Impl.ModelBase.BasicPublish(String exchange, String routingKey, Boolean mandatory, IBasicProperties basicProperties, ReadOnlyMemory`1 body)
//    at RabbitMQ.Client.Impl.AutorecoveringModel.BasicPublish(String exchange, String routingKey, Boolean mandatory, IBasicProperties basicProperties, ReadOnlyMemory`1 body)
// IsClosed:True
// IsClosed:False

Is this the correct behavior?

@michaelklishin
Copy link
Member

You are supposed to close the channel before disposing it but I guess as a usability improvement we can update the state, too.

According to the stack trace the node was forced to shut down, so there may be connection recovery side effects at play.

@lukebakken lukebakken added this to the 6.2.5 milestone Mar 15, 2022
@lukebakken lukebakken self-assigned this Mar 15, 2022
@lukebakken lukebakken modified the milestones: 6.2.5, 6.3.0, 7.0.0 May 6, 2022
lukebakken added a commit that referenced this issue Dec 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants