mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2024-11-22 01:36:29 -05:00
fix(backend): prevent realtime connections getting prepared for closed websocket
The setAdapter function checks if the websocket is closed. If this is the case then an error is thrown and the whole process will be canceled. If the adapter isn't set before the realtime connection object is prepared then the connection will subscribe to all the events and THEN the process will be canceled. Because the MessageTransporter has no adapter (and won't get one), the connection will never get a disconnect event and clean up. This causes the flood of "cant send message over closed websocket" messages. Signed-off-by: Tilman Vatteroth <git@tilmanvatteroth.de>
This commit is contained in:
parent
f15aed3ed3
commit
bb54746ccf
1 changed files with 5 additions and 3 deletions
|
@ -87,20 +87,22 @@ export class WebsocketGateway implements OnGatewayConnection {
|
||||||
await this.realtimeNoteService.getOrCreateRealtimeNote(note);
|
await this.realtimeNoteService.getOrCreateRealtimeNote(note);
|
||||||
|
|
||||||
const websocketTransporter = new MessageTransporter();
|
const websocketTransporter = new MessageTransporter();
|
||||||
|
websocketTransporter.setAdapter(
|
||||||
|
new BackendWebsocketAdapter(clientSocket),
|
||||||
|
);
|
||||||
|
|
||||||
const permissions = await this.noteService.toNotePermissionsDto(note);
|
const permissions = await this.noteService.toNotePermissionsDto(note);
|
||||||
const acceptEdits: boolean = userCanEdit(
|
const acceptEdits: boolean = userCanEdit(
|
||||||
permissions as NotePermissions,
|
permissions as NotePermissions,
|
||||||
user?.username,
|
user?.username,
|
||||||
);
|
);
|
||||||
|
|
||||||
const connection = new RealtimeConnection(
|
const connection = new RealtimeConnection(
|
||||||
websocketTransporter,
|
websocketTransporter,
|
||||||
user,
|
user,
|
||||||
realtimeNote,
|
realtimeNote,
|
||||||
acceptEdits,
|
acceptEdits,
|
||||||
);
|
);
|
||||||
websocketTransporter.setAdapter(
|
|
||||||
new BackendWebsocketAdapter(clientSocket),
|
|
||||||
);
|
|
||||||
|
|
||||||
realtimeNote.addClient(connection);
|
realtimeNote.addClient(connection);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue