Skip to content

Commit

Permalink
fix handling of destroyed/errored streams in waitDrain()
Browse files Browse the repository at this point in the history
  • Loading branch information
eldargab committed Mar 17, 2024
1 parent cfb0a61 commit c2fd843
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/util-internal-http-server",
"comment": "remove unused import statement",
"type": "patch"
}
],
"packageName": "@subsquid/util-internal-http-server"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"changes": [
{
"packageName": "@subsquid/util-internal",
"comment": "fix handling of destroyed/errored streams in `waitDrain()`",
"type": "patch"
}
],
"packageName": "@subsquid/util-internal"
}
1 change: 0 additions & 1 deletion util/util-internal-http-server/src/app.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {createLogger, Logger} from '@subsquid/logger'
import assert from 'assert'
import * as buffer from 'buffer'
import {HttpContext, HttpContextOptions, HttpRequest, HttpResponse} from './ctx'
import {isHttpError} from './http-error'
import {GetPatternParams, PathPattern} from './path-pattern'
Expand Down
7 changes: 4 additions & 3 deletions util/util-internal/src/io.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import {ensureError} from './misc'

export function waitDrain(out: Writable): Promise<void> {
return new Promise((resolve, reject) => {
if (!out.writableNeedDrain) return resolve()

if (!out.writable) {
// https://github.com/nodejs/node/issues/42610
if (!out.writable || out.destroyed || out.errored || out.writableEnded) {
return reject(new Error('output stream is no longer writable'))
}

if (!out.writableNeedDrain) return resolve()

function cleanup() {
out.removeListener('error', error)
out.removeListener('drain', drain)
Expand Down

0 comments on commit c2fd843

Please sign in to comment.