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.
Fixes issue #75
This is my first open source pull request so I apologize for any formatting issues. Additionally, I don't know the repository as well as others so there may be a better way to implement the fix.
I believe I found the root cause of this. I added a pull request to fix, but I'm going to copy/paste what I believe is causing the error.
The main issue in the code is inside raw_client.rs inside the
recv
method implementation (snippet below):rust-electrum-client/src/raw_client.rs
Lines 671 to 685 in 805ea0a
When this is first called, the
self._reader_thread
will run. Inside theself._reader_thread
, if the request id matches the response id, everything works fine. However, if the request id does not match the response id, we run the following code:rust-electrum-client/src/raw_client.rs
Lines 602 to 612 in 805ea0a
The channel that the response is sent back into is not unique, but rather all the channels share the same sender.clone() and receiver. The only validation that is done is to check that the request id is still being searched for inside
self.waiting_map
. This means that the receiver channel receives whatever the next response is into the channel without any validation that it matches the request id which happens herematch receiver.recv()?
.This is fixed by implementing unique channels for every request id. This fix can be verified with the code @johnzweng used to show the issue
If you run this with the initial code, it will error out after 1-10 cycles normally. However, after the fix this runs indefinitely.