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

bugfix: Fix resource leaks in the WebSocket engine #253

Conversation

tai-kun
Copy link
Contributor

@tai-kun tai-kun commented May 5, 2024

Thank you for the great work on this project.

What is the motivation?

Recently, CI has been failing due to WebSocket resource leaks.

Surreal's close method waits until the engine it is using transitions to a "disconnected" status. However, the WebSocket engine's disconnect method immediately transitions to the "disconnected" status after requesting that the socket be disconnected. The close method of socket (not Surreal) only requests that the connection be closed, and certainly does not wait for the connection to close. Therefore, if the socket "close" event occurs before setStatus is resolved, there will be no resource leak, but if setStatus is resolved first, a resource leak will occur.

a

What does this change do?

In order to detect a WebSocket disconnection, prevent the WebSocket engine from immediately transitioning to the "disconnected" status.

What is your testing strategy?

I have verified that all existing tests pass.

Is this related to any issues?

N/A

Have you read the Contributing Guidelines?

In order to detect a WebSocket disconnection, prevent the WebSocket engine from immediately transitioning to the disconnected state.
@tai-kun tai-kun requested a review from kearfy as a code owner May 5, 2024 02:56
Copy link
Member

@kearfy kearfy left a comment

Choose a reason for hiding this comment

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

Very good catch, thank you @tai-kun!

@kearfy kearfy merged commit 44fd11e into surrealdb:main May 6, 2024
@tai-kun tai-kun deleted the bugfix-fix-resource-leaks-in-the-websocket-engine branch May 6, 2024 23:04
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

2 participants