hapi icon indicating copy to clipboard operation
hapi copied to clipboard

EPIPE errors from aborted request

Open joshkel opened this issue 4 years ago • 7 comments
trafficstars

Support plan

  • is this issue currently blocking your project? (yes/no): no
  • is this issue affecting a production system? (yes/no): yes

Context

  • node version: 14.18.0
  • module version with issue: 20.1.5
  • last module version without issue: unknown
  • environment (e.g. node, browser, native): Node
  • used with (e.g. hapi application, another framework, standalone, ...): hapi application
  • any other relevant information: N/A

What are you trying to achieve or the steps to reproduce?

Our Sentry setup has caught and logged the following error several times:

Error: write EPIPE
  File "internal/stream_base_commons.js", line 156, col 25, in afterWriteDispatched
  File "internal/stream_base_commons.js", line 147, col 3, in writeGeneric
  File "net.js", line 787, col 11, in Socket._writeGeneric
  File "net.js", line 799, col 8, in Socket._write
  File "internal/streams/writable.js", line 358, col 12, in writeOrBuffer
  File "internal/streams/writable.js", line 303, col 10, in Socket.Writable.write
  File "_http_outgoing.js", line 351, col 17, in ServerResponse._writeRaw
  File "_http_outgoing.js", line 327, col 15, in ServerResponse._send
  File "_http_outgoing.js", line 846, col 10, in ServerResponse.end
  File "/home/app/deploy/node_modules/@hapi/hapi/lib/transmit.js", line 318, col 21, in internals.end
    request.raw.res.end();                                          // Triggers injection promise resolve

This apparently happens when the client aborts its request; it's preceded by ["request","error","abort"] and ["response","error","aborted"] error messages.

We've gotten several errors like this, although I haven't yet tried to reproduce it locally or on demand.

What was the result you got?

An EPIPE error from an apparently uncaught exception.

What result did you expect?

No additional errors logged other than the abort message.

joshkel avatar Oct 05 '21 21:10 joshkel

Thanks for the report! Very timely— if you're interested you can check-out progress on a similar (or potentially the same?) issue in #4295.

devinivy avatar Oct 06 '21 03:10 devinivy

Hmm, we already test for errors during stream transmission, but not combined with a client abort. Guess we need another test case.

kanongil avatar Oct 06 '21 08:10 kanongil

Actually, this does not make sense.

The internals.end() method is called to handle the request 'aborted' event and then proceeds to call res.end().

Response will have the res.finished === false, so it will try to send a trailer to the shared socket.

Once it calls res._writeRaw(), it should just immediately return false, since the socket should have been destroyed.

This means that it should never even try to write. Unless maybe you have set the hidden server.httpAllowHalfOpen property to true?

kanongil avatar Oct 06 '21 10:10 kanongil

maybe related? https://github.com/nodejs/node/issues/40553

can you try node 14.17 instead of node 14.18?

mhassan1 avatar Oct 27 '21 15:10 mhassan1

Hi Folks! I'm upgrade my app to node 14 and @hapi/hapi: 20.0.0 and i'm getting

"message": "write EPIPE", "stack": Error: write EPIPE at afterWriteDispatched

this happen using node V14.18.1 orV14.15.5

aaestrada avatar Oct 29 '21 02:10 aaestrada

@aaestrada If you can reliably reproduce the issue, please file an issue.

kanongil avatar Oct 29 '21 08:10 kanongil

Regardless of what triggers this, hapi should probably handle thrown errors when calling request.raw.res.end().

kanongil avatar Oct 29 '21 11:10 kanongil