Skip to content

Commit f1ba9cf

Browse files
committed
add bun idleTimeout = 0
1 parent 9c0e64d commit f1ba9cf

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

src/routes/responses/handler.ts

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -52,29 +52,13 @@ export const handleResponses = async (c: Context) => {
5252
if (isStreamingRequested(payload) && isAsyncIterable(response)) {
5353
consola.debug("Forwarding native Responses stream")
5454
return streamSSE(c, async (stream) => {
55-
const pingInterval = setInterval(async () => {
56-
try {
57-
await stream.writeSSE({
58-
event: "ping",
59-
data: JSON.stringify({ timestamp: Date.now() }),
60-
})
61-
} catch (error) {
62-
consola.warn("Failed to send ping:", error)
63-
clearInterval(pingInterval)
64-
}
65-
}, 3000)
66-
67-
try {
68-
for await (const chunk of response) {
69-
consola.debug("Responses stream chunk:", JSON.stringify(chunk))
70-
await stream.writeSSE({
71-
id: (chunk as { id?: string }).id,
72-
event: (chunk as { event?: string }).event,
73-
data: (chunk as { data?: string }).data ?? "",
74-
})
75-
}
76-
} finally {
77-
clearInterval(pingInterval)
55+
for await (const chunk of response) {
56+
consola.debug("Responses stream chunk:", JSON.stringify(chunk))
57+
await stream.writeSSE({
58+
id: (chunk as { id?: string }).id,
59+
event: (chunk as { event?: string }).event,
60+
data: (chunk as { data?: string }).data ?? "",
61+
})
7862
}
7963
})
8064
}

src/start.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,9 @@ export async function runServer(options: RunServerOptions): Promise<void> {
111111
serve({
112112
fetch: server.fetch as ServerHandler,
113113
port: options.port,
114+
bun: {
115+
idleTimeout: 0,
116+
},
114117
})
115118
}
116119

0 commit comments

Comments
 (0)