Skip to content

Commit

Permalink
fix(use/http,use/http2,use/express,use/fastify): Check writable ins…
Browse files Browse the repository at this point in the history
…tead of `closed` before writing to response

Closes enisdenjo#69
  • Loading branch information
enisdenjo committed Aug 23, 2023
1 parent f653d48 commit 3c71f69
Show file tree
Hide file tree
Showing 4 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/use/express.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ export function createHandler<Context extends OperationContext = undefined>(
res.once('close', body.return);
for await (const value of body) {
const closed = await new Promise((resolve, reject) => {
if (res.closed) {
if (!res.writable) {
// response's close event might be late
resolve(true);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/use/fastify.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ export function createHandler<Context extends OperationContext = undefined>(
reply.raw.once('close', body.return);
for await (const value of body) {
const closed = await new Promise((resolve, reject) => {
if (reply.raw.closed) {
if (!reply.raw.writable) {
// response's close event might be late
resolve(true);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/use/http.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function createHandler<Context extends OperationContext = undefined>(
res.once('close', body.return);
for await (const value of body) {
const closed = await new Promise((resolve, reject) => {
if (res.closed) {
if (!res.writable) {
// response's close event might be late
resolve(true);
} else {
Expand Down
2 changes: 1 addition & 1 deletion src/use/http2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ export function createHandler<Context extends OperationContext = undefined>(
res.once('close', body.return);
for await (const value of body) {
const closed = await new Promise((resolve, reject) => {
if (res.closed) {
if (!res.writable) {
// response's close event might be late
resolve(true);
} else {
Expand Down

0 comments on commit 3c71f69

Please sign in to comment.