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.
What does this change do?
In order to detect a WebSocket disconnection, prevent the WebSocket engine from immediately transitioning to the "disconnected" status.
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'sdisconnect
method immediately transitions to the "disconnected" status after requesting that the socket be disconnected. Theclose
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 beforesetStatus
is resolved, there will be no resource leak, but ifsetStatus
is resolved first, a resource leak will occur.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?