-
Notifications
You must be signed in to change notification settings - Fork 140
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
Do not embed context in DeferredConfirmation #140
Conversation
This change removes embedded context.Context (which is generally an antipattern) from DeferredConfirmation. Instead, we use a simple channel to wait for ack/nack status. This approach is more flexible since it can be combined with timers, tickers, other contexts and channels in general using select{} statements and there is no overhead from context cancellation setup. Note that rabbitmq#96 introduced a behavior where Wait would unblock and return false once the context passed to Publish expires. This commit reverts this (arguably breaking) behavior in favor of WaitContext function.
Looks like an internal API that was accidentally exported. There seems to be no uses outside of the AMQP library, so should be safe to remove.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for contributing to this project. I like this idea of using channels instead of the embedded context. However, I'm not a fan of using sync/atomic
, unless it is strictly necessary. Have you tried to use mutexes instead?
On a second look, we don’t actually need other synchronization primitives as |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great and very clever use of channels 👍
Since this is a breaking change (change to public function signature), we will merge this for version 2.0.0. That will probably be after we release 1.6.0, which should be after we merge #145
I think we can make the change completely backwards compatible by
What do you think? It’d also be nice to add |
I don‘t think that this PR introduces breaking changes aside from removing I didn’t run |
After having a second look, you are right, this PR is arguably breaking. It is true that we are removing |
@lukebakken tagging you since you assigned yourself first 🙂 Are you happy with the outcome of this conversation? In summary:
|
19e503a is part of this PR, it addresses my first round of feedback 😄 |
That's weird, when I originally clicked on the commit github said it did not exist on any branch. It's working now at least. |
Sorry, I am late on the subject. Yes this is not the idiomatic way to use context in struct but it was the only way I found to cancel the confirmation without too much breaking. This PR is clearly a better implementation. The only downside I see is that we can't really expire a confirmation and it would be kept open until next message with multiple ack but the wait can still be non blocking which still solve the main problem I encounter. Sidenote: since context is not needed for publish anymore, |
Also probably examples need to be updated as they may imply some logic that is not really true anymore since context on publish is ignored. |
I'm not sure I understand this point. Do you mean that, the removal of |
This change removes embedded
context.Context
(which is generally an anti-pattern) fromDeferredConfirmation
. Instead, we use a simple channel to wait for ack/nack status. This approach is more flexible since it can be combined with timers, tickers, other contexts and channels in general usingselect{}
statements and there is no overhead from context cancellation setup.Note that #96 introduced a behavior where
Wait
would unblock and return false once the context passed toPublish
expires. This commit reverts this (arguably breaking) behavior in favor ofWaitContext
function.