Skip to content

long delay in Connection creation on cancellation #1921

@JanEggers

Description

@JanEggers

Describe the bug

I discovered this while testing. when a tests fails due to some assert I dispose a service that manages my rabbitmq clients. first thing in there is triggering a cancellation token so all initialization attempts are aborted. the rabbitmq client is stuck in this callstack for more than 10 seconds for each client so my tests run into a timeout inside of dispose:

Image

Reproduction steps

whenever the time is less or more it seems to work properly on my machine so you may need to adjust the delay to hit the stack mentioned above.

[TestClass]
public class RabbitRepro
{
	private static readonly RabbitMqContainer RabbitMqContainer = new RabbitMqBuilder("rabbitmq:4-management")
		.Build();

	[TestMethod]
	public async Task TestCreateClientWithCancellation()
	{
		await RabbitMqContainer.StartAsync();

		var factory = new ConnectionFactory
		{
			Uri = new Uri(RabbitMqContainer.GetConnectionString()),
			AutomaticRecoveryEnabled = true
		};

		using var cts = new CancellationTokenSource();
		cts.CancelAfter(TimeSpan.FromMilliseconds(20));

		await factory.CreateConnectionAsync(cts.Token);
	}
}

Expected behavior

CreateConnectionAsync and its internals should respect the cancellation request and throw as soon as cancellation is requested and not be stuck somewhere for a long time.

what I have seen while debugging is that Channel.DisposeAsync calls CloseAsync which is stuck because its waiting for a response from the server which is not comming because the underlying connection is already closed / not opened yet

Additional context

rabbitmq client 7.2

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions