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

Make sure OnCallbackException is executed for AsyncConsumers #946

Merged
merged 7 commits into from
Sep 30, 2020

Conversation

BarShavit
Copy link
Contributor

@BarShavit BarShavit commented Sep 25, 2020

Proposed Changes

Always call to await when executing a task in AsyncConsumerWorkService. Previously, the wait called only if the job hasn't done yet. It lead to missing exception and missed the invoke of OnCallbackException event.

Types of Changes

What types of changes does your code introduce to this project?
Put an x in the boxes that apply

Checklist

Put an x in the boxes that apply. You can also fill these out after creating
the PR. If you're unsure about any of them, don't hesitate to ask on the
mailing list. We're here to help! This is simply a reminder of what we are
going to look for before merging your code.

  • I have read the CONTRIBUTING.md document
  • I have signed the CA (see https://cla.pivotal.io/sign/rabbitmq)
  • All tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)
  • Any dependent changes have been merged and published in related repositories

…e. Previously, the wait called only if the job hasn't done yet. It lead to missing exception and missed the invoke of OnCallbackException event.
@michaelklishin michaelklishin changed the title Bug/callback exception Make sure OnCallbackException is executed for AsyncConsumers Sep 25, 2020
Checking manually for exceptions with task.Exception.
object o = new object();
bool notified = false;
string q = _model.QueueDeclare();

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit 🔥 extra line

projects/Unit/TestAsyncConsumerExceptions.cs Show resolved Hide resolved
@bollhals
Copy link
Contributor

Are you sure the tests are testing the correct thing?
(They are not very strict about what they verify the success of. Just that a exception was thrown.)

If I debug them, I get the exception thrown by throw new InvalidOperationException("Should never be called."); from AsyncDefaultBasicConsumer.cs

Also if I use the tests on master, they're green with or without your changes.

@danielmarbach
Copy link
Collaborator

@bollhals good catch. Honestly I was a bit lazy in reviewing the tests and mostly looked at the implementation side of things. Will take extra care next time (although I confess I was just about going on leave yesterday and I think that cause me to take shortcuts)

@BarShavit
Copy link
Contributor Author

Copied the tests from the sync version.
Fixed that, now it fails without the changes.
The bug happened only if the registered received method is async. Also need to mark "DispatchConsumersAsync" as true, or it go to the default class and throws the exception throw new InvalidOperationException("Should never be called.");.

The task.delay(0) is just to avoid warnings (async without await in the method).

@bollhals
Copy link
Contributor

I did some quick tests regarding performance of this change

Method Mean Error StdDev Median Ratio
IsCompleted 23.24 ns 0.138 ns 0.202 ns 23.24 ns 1.00
Await 27.88 ns 0.055 ns 0.080 ns 27.86 ns 1.20
GetResult 23.62 ns 0.199 ns 0.297 ns 23.47 ns 1.02
RanToCompletion 25.08 ns 0.072 ns 0.106 ns 25.08 ns 1.08

So the currently suggested change seems like the most promising one!

Check the received exception in the test to verify it's the same.
@michaelklishin
Copy link
Member

Thank you for sticking with it @BarShavit!

@bollhals
Copy link
Contributor

This one can and should probably go back into 6.x

@michaelklishin michaelklishin merged commit ef8eaf4 into rabbitmq:master Sep 30, 2020
michaelklishin added a commit that referenced this pull request Sep 30, 2020
Make sure OnCallbackException is executed for AsyncConsumers

(cherry picked from commit ef8eaf4)
@michaelklishin
Copy link
Member

Backported to 6.x.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants