Skip to content

Commit

Permalink
fix(core): fix AbortController abort stream body, close #4
Browse files Browse the repository at this point in the history
  • Loading branch information
shigma committed Mar 25, 2024
1 parent 3247ea2 commit 02e260f
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions packages/core/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -255,12 +255,13 @@ export class HTTP extends Service<HTTP.Config> {
const timer = config.timeout && setTimeout(() => {
controller.abort(new HTTPError('request timeout', 'ETIMEDOUT'))
}, config.timeout)
return () => {
return (done?: boolean) => {
clearTimeout(timer)
if (done) return
controller.abort(new HTTPError('context disposed', 'ETIMEDOUT'))
}
})
controller.signal.addEventListener('abort', dispose)
controller.signal.addEventListener('abort', () => dispose())

try {
const headers = new Headers(config.headers)
Expand Down Expand Up @@ -317,7 +318,7 @@ export class HTTP extends Service<HTTP.Config> {
}
return response
} finally {
controller.abort()
dispose(true)
}
}

Expand Down
1 change: 1 addition & 0 deletions packages/file/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface FileResponse {
}

export const name = 'undios-file'
export const inject = ['http']

export interface Config {}

Expand Down

0 comments on commit 02e260f

Please sign in to comment.