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

Assign event listener to socket close event on open before attempting post-open logic #1186

Merged
merged 7 commits into from Jan 28, 2020
Merged

Assign event listener to socket close event on open before attempting post-open logic #1186

merged 7 commits into from Jan 28, 2020

Conversation

nickewansmith
Copy link
Contributor

This commit adds the Connection _ws.close event listener post _ws.open before executing any post _ws.open logic, i.e. Connection._subscribeToLedger. This prevents a reconnection error loop that occurs if Connection._ws is never cleaned up by the unreachable _ws.close event listener. Also, this ensures that a possible disconnect() promise rejection is not unhandled if any _ws.open logic in Connection.connect() throws.

… to execute post-connection logic, prottects possible unhandled rejection in disconnect
Copy link
Contributor

@0xCLARITY 0xCLARITY left a comment

Choose a reason for hiding this comment

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

I'm not that familiar with this code / WebSockets, so I'm going to see if I understand the problem here.

We handle cleanup in the _ws.close event listener. However, previously we were setting up the _ws.close listener too late, and we were getting an error after opening the connection, but before setting up the _ws.close event listener responsible for cleanup.

That would result in subsequent reconnection errors, because we had failed to clean up before. Is that all correct?

src/common/connection.ts Outdated Show resolved Hide resolved
@nickewansmith nickewansmith requested review from FKSRipple and removed request for intelliot and FKSRipple January 24, 2020 21:49
Copy link
Contributor

@FredKSchott FredKSchott left a comment

Choose a reason for hiding this comment

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

A few comments on the test, but overall this change is solid. Thanks again for filing & fixing.

test/connection-test.ts Show resolved Hide resolved
test/connection-test.ts Outdated Show resolved Hide resolved
Copy link
Collaborator

@intelliot intelliot left a comment

Choose a reason for hiding this comment

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

Haven't tested this out but it looks good to me

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.

None yet

4 participants