Memory leak: window.onbeforeunload listener added for every new connection#65
Conversation
jourdain
left a comment
There was a problem hiding this comment.
This is mandatory and related to trame life cyle for user hooks in python.
This life cycle hooks are to allow an application developer to know when a client connects and disconnects. So we could include it in |
The lifecycle user hooks will still work, as long as you are firing the user hooks when one of the following happens:
|
Oh yes, I am not saying to remove that, I agree with you on that. Just that the |
|
The heartbeat is handle at the transport level and not at the application layer.
Except that right now, none of those will trigger that method call on the server. |
|
Since this is just for the |
The thing is, browser crash |
|
Which one of these close/destroy/disconnect/exit methods should send the const trame = new Trame();
const client = trame.client!;
const connection = client.getConnection()!;
const session = connection.getSession()!;
await session.close();
connection.destroy();
client.disconnect(disconnectTimeout);
trame.exit(disconnectTimeout);
trame.disconnect(); |
|
It should be done at the trame api class and not in the client. Add the call in disconnect() {
if (this.isConnected()) {
this.client?.getRemote()?.Trame?.lifeCycleUpdate("client_exited");
this.client.disconnect(0);
}
}
exit(timeout = 60) {
if (this.isConnected()) {
this.client?.getRemote()?.Trame?.lifeCycleUpdate("client_exited");
this.client.disconnect(timeout);
}
}Then your current change will be fine. |
Done |
|
Can you?
|
…isconnect/exit call
6001b3e to
93776d0
Compare
Done. Let me know if I got something wrong |
@jourdain With every new
Trameconnection made in JavaScript, awindow.onbeforeunloadevent listener is added, that attempts to phone home:trame-client/js-lib/src/trame.js
Lines 163 to 165 in 9345828
This leaks an un-disposable Trame object every time the listener is added.
In other words, even if you call
trame.exit()andtrame.disconnect()on your connection when you're done, andnullout all of your references, theTrameobject is still lives on in the global scope.The better way to do this is to send a "heartbeat" signal periodically to the server, to tell the server that the connection is still active. If a heartbeat is not received after a time limit, the server should then consider the client to be de-facto disconnected.
This PR removes the
beforeunloadlistener. I have not investigated on whether a heartbeat is being sent already so I'm not sure if there is also server-side work that needs to be done.