Skip to content
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

🐛 Fix connect lock issues #1

Merged
merged 1 commit into from
Nov 17, 2022
Merged

🐛 Fix connect lock issues #1

merged 1 commit into from
Nov 17, 2022

Conversation

alecgibson
Copy link

This change fixes two issues described here:
pladaria#165

  1. It's impossible to reconnect after maxRetries is exceeded, because the lock is never released
  2. It's impossible to reconnect if close() was called before the connection has been established

This change adds tests and fixes as discussed in the above issue.

@@ -1,6 +1,6 @@
{
"name": "@reedsy/reconnecting-websocket",
"version": "4.4.0-reedsy-1.0.0",
"version": "4.4.0-reedsy-1.0.1",

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really want to have version with reedsy if the package is called @reedsy/reconnectiong-websocket?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's nice: it encodes the upstream version we're on (which we can upgrade later if it also upgrades), and specifies our own internal reedsy version. It's what we're already doing in quill

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 We do not use this in all forked packages I guess we should unify it then

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how to install it?npm install @reedsy/[email protected],always fail,not found

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link

@FairyWorld FairyWorld Jan 9, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

#1 (comment)

Method 1 is not available. I tried to install according to the configuration in the document, but still failed to install. Method 2 is OK, but it is troublesome to configure "@reedsy:registry=https://npm.pkg.github.com" and "github token" of. npmrc by the company owner。

According to the prompts in the figure below, the following configuration failed in the window system

image

@@ -376,6 +376,7 @@ export default class ReconnectingWebSocket {
.then(url => {
// close could be called before creating the ws
if (this._closeCalled) {
this._connectLock = false;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They said to add this._connectLock = false in close also

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think they're incorrect, though. Adding it in the close() method adds a subtle bug. I've added a test case rapidly toggling connection to capture it. You should see if you do as they suggest, the test fails.

The issue is that if you set _connectLock = false in the close() method, you open up this case:

  1. Connect. We pass the _connectLock check, so we start a _wait()
  2. Now call close() which in this case sets _connectLock = false
  3. Call reconnect(), which internally calls _connect(). Now, since we've reset _connectLock = false in close(), we pass the _connect() _connectLock check again, and set up a second _wait(), while the first hasn't finished
  4. If we wait for these promises to resolve, we now create two WebSocket connections instead of one

This change fixes two issues described here:
pladaria#165

 1. It's impossible to reconnect after `maxRetries` is exceeded, because
    the lock is never released
 2. It's impossible to reconnect if `close()` was called before the
    connection has been established

This change adds tests and fixes as discussed in the above issue.
@alecgibson alecgibson merged commit 9407876 into main Nov 17, 2022
@alecgibson alecgibson deleted the reconnect-lock branch November 17, 2022 13:56
@dowmeister
Copy link

Thanks for this PR, works perfectly.
I wanted to install your fork via npm but fire error for package not found

@alecgibson
Copy link
Author

@shardick we haven't released it on NPM. You can either:

  • add it as a Github URL; or
  • add @reedsy:registry=https://npm.pkg.github.com to .npmrc

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants