surrealdb / surrealdb.js

SurrealDB SDK for JavaScript
https://surrealdb.com
Apache License 2.0
271 stars 46 forks source link

bugfix: Fix resource leaks in the WebSocket engine #253

Closed tai-kun closed 2 months ago

tai-kun commented 2 months ago

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?