6.x: Guard against null when removing ShutdownHandler #1859
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Proposed Changes
Solving Bug #1858
A race condition occurs when a RabbitMQ client and server simultaneously try to cancel the same consumer. This can happen, for example, if the queue being consumed is deleted on the server at the same moment the client cancels the consumer.
This creates a conflict in ModelBase.cs between the
HandleBasicCancel
andHandleBasicCancelOk
methods. Both methods attempt to remove the consumer, but they operate differently:HandleBasicCancel
is initiated by the server and directly removes the consumer.HandleBasicCancelOk
is a confirmation from the server for a client-initiated cancellation. It tries to schedule a final action using the consumer object.If
HandleBasicCancel
executes first, it removes the consumer. WhenHandleBasicCancelOk
subsequently runs, it attempts to operate on a consumer that no longer exists, leading to an error whenBasicCancel
tries to remove the Shutdown EventHandler.The fix for this race condition is relatively straightforward. The solution is to process the cancellation requests on a FCFS basis while adding null checks to ensure that all subsequent methods to execute does not cause an error by trying to access a consumer that has already been removed. (To my Knowlage it is only
HandleBasicCancel
andHandleBasicCancelOk
)Types of Changes
What types of changes does your code introduce to this project?
Put an
x
in the boxes that applyChecklist
CONTRIBUTING.md
documentFurther Comments