Skip to content

Commit 6495440

Browse files
authored
ensure socket close events are not errors in RpcServer (#4860)
1 parent ba7d7e0 commit 6495440

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

.changeset/tiny-impalas-tease.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@effect/rpc": patch
3+
---
4+
5+
ensure socket close events are not errors in RpcServer

packages/rpc/src/RpcServer.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,7 +1188,7 @@ const makeSocketProtocol = Effect.gen(function*() {
11881188
}
11891189
clients.set(id, { write })
11901190

1191-
yield* Effect.orDie(Effect.interruptible(socket.runRaw((data) => {
1191+
yield* socket.runRaw((data) => {
11921192
try {
11931193
const decoded = parser.decode(data) as ReadonlyArray<FromClientEncoded>
11941194
if (decoded.length === 0) return Effect.void
@@ -1201,7 +1201,11 @@ const makeSocketProtocol = Effect.gen(function*() {
12011201
} catch (cause) {
12021202
return writeRaw(parser.encode(ResponseDefectEncoded(cause)))
12031203
}
1204-
})))
1204+
}).pipe(
1205+
Effect.interruptible,
1206+
Effect.catchIf((error) => error.reason === "Close", () => Effect.void),
1207+
Effect.orDie
1208+
)
12051209
}
12061210

12071211
const protocol = yield* Protocol.make((writeRequest_) => {

0 commit comments

Comments
 (0)