Skip to content

Commit e2f252a

Browse files
authored
fix(stream): upgrade @hono/node-server to v2 and fix abort handling (#4940)
1 parent 54f2f0c commit e2f252a

5 files changed

Lines changed: 13 additions & 15 deletions

File tree

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ jobs:
129129
runs-on: ubuntu-latest
130130
strategy:
131131
matrix:
132-
node: ['18.18.2', '20.x', '22.x']
132+
node: ['20.x', '22.x', '24.x']
133133
steps:
134134
- uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6
135135
- uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6

‎bun.lock‎

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎package.json‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -657,7 +657,7 @@
657657
],
658658
"devDependencies": {
659659
"@hono/eslint-config": "^2.1.0",
660-
"@hono/node-server": "^1.13.5",
660+
"@hono/node-server": "^2.0.2",
661661
"@types/glob": "^9.0.0",
662662
"@types/jsdom": "^21.1.7",
663663
"@types/node": "^24.3.0",

‎runtime-tests/node/index.test.ts‎

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,12 @@ describe('stream', () => {
133133

134134
it('Should call onAbort', async () => {
135135
const controller = new AbortController()
136-
const res = expect(agent.get('/stream', { signal: controller.signal })).rejects.toThrow(
137-
'This operation was aborted'
138-
)
136+
const req = agent.get('/stream', { signal: controller.signal })
139137

140138
expect(aborted).toBe(false)
141139
await new Promise((resolve) => setTimeout(resolve, 10))
142140
controller.abort()
143-
await res
141+
await req.catch(() => {})
144142
while (!aborted) {
145143
await new Promise((resolve) => setTimeout(resolve))
146144
}
@@ -188,14 +186,12 @@ describe('streamSSE', () => {
188186

189187
it('Should call onAbort', async () => {
190188
const controller = new AbortController()
191-
const res = expect(agent.get('/stream', { signal: controller.signal })).rejects.toThrow(
192-
'This operation was aborted'
193-
)
189+
const req = agent.get('/stream', { signal: controller.signal })
194190

195191
expect(aborted).toBe(false)
196192
await new Promise((resolve) => setTimeout(resolve, 10))
197193
controller.abort()
198-
await res
194+
await req.catch(() => {})
199195
while (!aborted) {
200196
await new Promise((resolve) => setTimeout(resolve))
201197
}

‎src/utils/stream.ts‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,9 @@ export class StreamingApi {
3838
done ? controller.close() : controller.enqueue(value)
3939
},
4040
cancel: () => {
41-
this.abort()
41+
if (!this.closed) {
42+
this.abort()
43+
}
4244
},
4345
})
4446
}
@@ -65,12 +67,12 @@ export class StreamingApi {
6567
}
6668

6769
async close() {
70+
this.closed = true
6871
try {
6972
await this.writer.close()
7073
} catch {
7174
// Do nothing. If you want to handle errors, create a stream by yourself.
7275
}
73-
this.closed = true
7476
}
7577

7678
async pipe(body: ReadableStream) {

0 commit comments

Comments
 (0)