Skip to content

Commit

Permalink
Close connection on client close
Browse files Browse the repository at this point in the history
Signed-off-by: Marcos Candeia <[email protected]>
  • Loading branch information
mcandeia committed Mar 20, 2024
1 parent abda2b0 commit 12a503d
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -265,8 +265,10 @@ export class Realtime implements DurableObject {

socket.addEventListener(
"close",
() =>
this.sessions = this.sessions.filter((s) => s.socket !== socket),
(cls) => {
this.sessions = this.sessions.filter((s) => s.socket !== socket);
socket.close(cls.code, "Durable Object is closing WebSocket")
},
);

socket.accept();
Expand Down

0 comments on commit 12a503d

Please sign in to comment.