This repository was archived by the owner on Dec 21, 2021. It is now read-only.
Handle disconnecting during publish. #59
Merged
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.
You may have noticed the following error being logged when running the integration tests:
https://travis-ci.com/streamr-dev/streamr-client-javascript/jobs/191090350#L2869-L2884
The above gets logged during running the current integration tests, yet the test suite does not fail because no test is actually listening for the client 'error' event at the time it occurs. It seems to be caused by the test suite itself not waiting for the publish action to finish before disconnecting the client. It appears the message does fail to be published.
Note the code below from the current
master
branch:streamr-client-javascript/src/StreamrClient.js
Lines 269 to 272 in 39db82d
createStreamMessage
is async, so it's entirely possible that the client will fully or partially disconnect between the firstisConnected
check andcreateStreamMessage
resolving. This causes the_requestPublish
to try writing to the disconnecting websocket, which in turn triggers the above error event, which isn't caught by anything.This PR makes
publish
re-check the client is connected try to reconnect ifautoConnect
is set, or fail with an error "Disconnected before publish" otherwise.Also adjusted the tests that initially exhibited this error to
await
their operations before continuing.Update: Noticed similar behaviour for subscriptions: if you call
client.disconnect()
onsubscribed
, and the subscription had resend options, the client will cough up a similar error event as it tries to write to a closing websocket:Solved this in 1fbd711 by simply ignoring resend requests if the client is no longer connected. A more general solution should probably be found.