@@ -157,7 +157,7 @@ index c586c60..49886d8 100644
157157 });
158158 });
159159 const onStreamRequest = Effect.fnUntraced(function* (rpc, middleware, payload, headers, streamBufferSize, context) {
160- @@ -143,11 +150,17 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
160+ @@ -143,11 +150,18 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
161161 });
162162 const fiber = Fiber.getCurrent();
163163 const id = generateRequestId();
@@ -173,11 +173,12 @@ index c586c60..49886d8 100644
173173+ if (!entry) return Effect.void;
174174 entries.delete(id);
175175- return sendInterrupt(id, Exit.isFailure(exit) ? Array.from(Cause.interruptors(exit.cause)) : [], context);
176- + return sendInterrupt(id, Exit.isFailure(exit) ? Array.from(Cause.interruptors(exit.cause)) : [], context, entry.rpc._tag);
176+ + // Shutting down releases a socket reader blocked offering into this full buffer.
177+ + return Queue.shutdown(entry.queue).pipe(Effect.andThen(sendInterrupt(id, Exit.isFailure(exit) ? Array.from(Cause.interruptors(exit.cause)) : [], context, entry.rpc._tag)));
177178 });
178179 const queue = yield* Queue.bounded(streamBufferSize);
179180 entries.set(id, {
180- @@ -155,9 +168 ,10 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
181+ @@ -155,9 +169 ,10 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
181182 rpc,
182183 queue,
183184 scope,
@@ -190,7 +191,7 @@ index c586c60..49886d8 100644
190191 message,
191192 context,
192193 discard: false
193- @@ -172,7 +186 ,7 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
194+ @@ -172,7 +187 ,7 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
194195 sampled: span.sampled
195196 } : {}),
196197 headers: Headers.merge(fiber.getRef(CurrentHeaders), headers)
@@ -199,7 +200,7 @@ index c586c60..49886d8 100644
199200 captureStackTrace: false
200201 }) : identity, Effect.catchCause(error => Queue.failCause(queue, error)), Effect.interruptible, Effect.forkIn(scope, {
201202 startImmediately: true
202- @@ -202,7 +216 ,10 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
203+ @@ -202,7 +217 ,10 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
203204 });
204205 };
205206 };
@@ -211,7 +212,7 @@ index c586c60..49886d8 100644
211212 const parentFiber = Fiber.getCurrent();
212213 const fiber = options.onFromClient({
213214 message: {
214- @@ -216,7 +233 ,7 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
215+ @@ -216,7 +234 ,7 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
215216 fiber.addObserver(() => {
216217 resume(Effect.void);
217218 });
@@ -220,7 +221,7 @@ index c586c60..49886d8 100644
220221 const write = message => {
221222 switch (message._tag) {
222223 case "Chunk":
223- @@ -224,7 +241 ,13 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
224+ @@ -224,7 +242 ,13 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
224225 const requestId = message.requestId;
225226 const entry = entries.get(requestId);
226227 if (!entry || entry._tag !== "Queue") return Effect.void;
@@ -235,7 +236,7 @@ index c586c60..49886d8 100644
235236 message: {
236237 _tag: "Ack",
237238 requestId: message.requestId
238- @@ -239,11 +262 ,18 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
239+ @@ -239,11 +263 ,18 @@ export const makeNoSerialization = /*#__PURE__*/Effect.fnUntraced(function* (gro
239240 const entry = entries.get(requestId);
240241 if (!entry) return Effect.void;
241242 entries.delete(requestId);
@@ -257,7 +258,7 @@ index c586c60..49886d8 100644
257258 }
258259 case "Defect":
259260 {
260- @@ -598,7 +628 ,7 @@ export const makeProtocolSocket = options => Protocol.make(Effect.fnUntraced(fun
261+ @@ -598,7 +629 ,7 @@ export const makeProtocolSocket = options => Protocol.make(Effect.fnUntraced(fun
261262 // `parser` is replaced on every connect, and a stateful serialization
262263 // encodes against the connection it is writing to, so the ping is encoded
263264 // when it is sent rather than once up front.
@@ -266,7 +267,7 @@ index c586c60..49886d8 100644
266267 let currentError;
267268 const broadcast = response => Effect.forEach(clientIds, clientId => writeResponse(clientId, response));
268269 const broadcastError = error => {
269- @@ -618,8 +648 ,7 @@ export const makeProtocolSocket = options => Protocol.make(Effect.fnUntraced(fun
270+ @@ -618,8 +649 ,7 @@ export const makeProtocolSocket = options => Protocol.make(Effect.fnUntraced(fun
270271 body: () => {
271272 const response = responses[i++];
272273 if (response._tag === "Pong") {
@@ -276,7 +277,7 @@ index c586c60..49886d8 100644
276277 }
277278 if (Object.hasOwn(response, "requestId")) {
278279 const requestId = response.requestId;
279- @@ -664,12 +693 ,12 @@ export const makeProtocolSocket = options => Protocol.make(Effect.fnUntraced(fun
280+ @@ -664,12 +694 ,12 @@ export const makeProtocolSocket = options => Protocol.make(Effect.fnUntraced(fun
280281 yield* processData(frames[i]);
281282 }
282283 }
@@ -291,7 +292,7 @@ index c586c60..49886d8 100644
291292 }).pipe(Option.isSome(hooks) ? Effect.ensuring(hooks.value.onDisconnect) : identity, Effect.tapCause(cause => {
292293 const error = Cause.findError(cause);
293294 const hasError = Result.isSuccess(error);
294- @@ -710,20 +739 ,28 @@ export const makeProtocolSocket = options => Protocol.make(Effect.fnUntraced(fun
295+ @@ -710,20 +740 ,28 @@ export const makeProtocolSocket = options => Protocol.make(Effect.fnUntraced(fun
295296 };
296297 }));
297298 const defaultRetryPolicy = /*#__PURE__*/Schedule.min([/*#__PURE__*/Schedule.exponential(500, 1.5), /*#__PURE__*/Schedule.spaced(5000)]);
@@ -325,7 +326,7 @@ index c586c60..49886d8 100644
325326 }).pipe(Effect.delay("5 seconds"), Effect.ignore, Effect.forever, Effect.interruptible, Effect.forkScoped);
326327 return {
327328 timeout: latch.await,
328- @@ -874,6 +911 ,11 @@ export const makeProtocolWorker = options => Protocol.make(Effect.fnUntraced(fun
329+ @@ -874,6 +912 ,11 @@ export const makeProtocolWorker = options => Protocol.make(Effect.fnUntraced(fun
329330 * @since 4.0.0
330331 */
331332 export const layerProtocolWorker = /*#__PURE__*/flow(makeProtocolWorker, /*#__PURE__*/Layer.effect(Protocol));
0 commit comments