Provider destroy function broken
After migration from 0.6.3 to 0.8.2, provider.destroy() just temporally changes the connection status, but keeps living, firing unwanted events and causing memory leaks. There's no way right now to destroy a provider.
P.S.: Also, receiving some sort of structured changelog would be kindly appreciated
Not sure if this is the same cause, but I've also been noticing something that looks like a memory leak over time, with ysweet rarely giving back memory.
(the increase in the end is from me restarting the container)
The timeline also has periods of no use (especially at night), where I'd expect the memory usage to drop back down.
After migration from 0.6.3 to 0.8.2, provider.destroy() just temporally changes the connection status, but keeps living, firing unwanted events and causing memory leaks. There's no way right now to destroy a provider.
P.S.: Also, receiving some sort of structured changelog would be kindly appreciated
Mine is running normally. Please refer to the following changes.
Please modify the file /js-pkg/client/src/provider. Ts content:
export class YSweetProvider {
// ... Existing attributes ...
/** Reconnection control */
private shouldReconnect = true;
}
public async connect(): Promise<void> {
// ... There is already the content of the connect method ...
+ this.shouldReconnect = true;
}
public disconnect() {
this.setStatus(STATUS_OFFLINE)
if (this.websocket) {
+ /** Automatic reconnection is prohibited when manually disconnected */
+ this.shouldReconnect = false;
this.websocket.close()
}
}
private websocketClose(event: CloseEvent) {
this.emit(EVENT_CONNECTION_CLOSE, event)
this.setStatus(STATUS_ERROR)
this.clearHeartbeat()
this.clearConnectionTimeout()
- this.connect()
+ if (this.shouldReconnect) {
+ this.connect();
+ }
// Remove all awareness states except for our own.
awarenessProtocol.removeAwarenessStates(
this.awareness,
Array.from(this.awareness.getStates().keys()).filter(
(client) => client !== this.doc.clientID,
),
this,
)
}
private websocketError(event: Event) {
this.emit(EVENT_CONNECTION_ERROR, event)
this.setStatus(STATUS_ERROR)
this.clearHeartbeat()
this.clearConnectionTimeout()
- this.connect()
+ if (this.shouldReconnect) {
+ this.connect();
+ }
}
Then build and it can be destroyed normally npm run build