question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

IBus.Publish not respecting CancellationToken

See original GitHub issue

Is this a bug report?

Yes

Can you also reproduce the problem with the latest version?

Yes

Environment

  1. Operating system: Windows 10 x64 Build 1809
  2. Visual Studio version: 2019
  3. Dotnet version: Core 3.0
  4. MT version: 6.2.1

Steps to Reproduce

(Write your steps here:)

  1. Setup a RabbitMQ bus instance
  2. Create CancellationTokenSource instance that cancels after a period of time
  3. Call IBus.Publish

Expected Behavior

I would expect either IPublishEndpoint to behave similar to ISendEndpoint where if RabbitMQ is down it throws an exception immediately or the call to Publish would hang and the task would cancel when the time span specified is reached.

Actual Behavior

The task never completes and only shows the task as being cancelled after RabbitMQ service is back up.

Reproducible Demo

static async Task Main(string[] args) {
	var cts = new CancellationTokenSource();
	var bus = Bus.Factory.CreateUsingRabbitMq(cfg => {
		cfg.Host("localhost");
		cfg.ReceiveEndpoint("value-entered", e => {
			e.Consumer<Program>();
		});
	});
	try {
		await bus.StartAsync();
		// Stop the RabbitMQ service before publish
		cts.CancelAfter(TimeSpan.FromSeconds(15));
		await bus.Publish(new ValueEntered(), cts.Token);

		// *NOTE* Using a send endpoint when RabbitMQ is down causes an exception to throw immediately
		//var sendEndpoint = await bus.GetSendEndpoint(new Uri("rabbitmq://localhost/value-entered"));
		//await sendEndpoint.Send(new ValueEntered(), cts.Token);
	}
	catch (TaskCanceledException e) {
		Console.WriteLine($"Publish cancelled.  Message: {e.Message}");
	}
	catch (Exception err) {
		Console.WriteLine($"Error: {err.Message}");
	}
	finally {
		await bus.StopAsync();
	}
}

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:13 (6 by maintainers)

github_iconTop GitHub Comments

1reaction
lkomanetzcommented, Mar 24, 2020

Thank you again @phatboyg for looking at this and fixing it so quickly.

0reactions
mstrukovcommented, Mar 19, 2020

Good news! When do you think a new nuget package will be published with the fix?

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to cancel long running task in MassTransit
I found a solution so if i use this. e.Consumer(() => { return reqConume; //this is a singleton });. and as a singleton...
Read more >
Producers
Publish also supports cancellation, including timeouts. See the note above for details.
Read more >
How to stop automatic candidate insertion with ibus-table?
The “cancel” key binding (default: Esc ) doesn't select the candidate, but gets rid of the entered text entirely, so that's not helpful....
Read more >
Using MassTransit with RabbitMQ in ASP.NET Core
In this article, we are going to take a look at how we can use the open-source, distributed application library MassTransit in conjunction ......
Read more >
RabbitMQ: AMQP Channel Best Practices - Code rant
Do not mix publishing and consuming on the same channel. If you follow the suggestion above, it implies that you have dedicated channels...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found