Fix reader thread raising exceptions into wrong thread#170
Open
bmorrall wants to merge 2 commits into
Open
Conversation
2ee8437 to
615fcb7
Compare
615fcb7 to
3ee8b9b
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #169
Fixes the bug where reader thread exceptions were delivered via
Thread#raisetowhichever thread called
connect, rather than the thread actively using the connection.This made the client unsafe to use with connection pools or in any multi-threaded context.
What changed
Instead of capturing the connect-caller as a "parent" and using
Thread#raisetodeliver errors cross-thread, exceptions are now stored on the client instance under
a mutex:
Every public method that uses the socket (
publish,subscribe,get_packet) callscheck_for_exception!before proceeding. This re-raises the stored exception inwhichever thread is actually doing the work, and clears it atomically so it fires
exactly once.
Behaviour
disconnectandconnectboth clear the stored exception, so reconnect is always a clean slateMQTT::NotConnectedException(the normal not-connected path) rather than replaying the stale errorTests
The two specs that explicitly wired up
Thread.current[:parent]and expectedThread#raiseto be called have been updated to verify the new behaviour: that theexception is stored and re-raised by
check_for_exception!in the calling thread.