karlseguin / http.zig

An HTTP/1.1 server for zig
MIT License
533 stars 41 forks source link

Broken pipe error handling - skip code that attempts to write error details to the broken connection #14

Closed zigster64 closed 1 year ago

zigster64 commented 1 year ago

When there is an error due to a broken connection, the existing logic treats this as a standard error, which then calls an error handler and/or writes some error code to the response.

We should treat IO errors as a different case - and not attempt to write to the known-broken connection.

Attempting to write to the connection may also create some allocations that we wont need as well (ensureSpace on the buffer)

zigster64 commented 1 year ago

Note - broken connections are easy enough to replicate when you have long running SSE handlers.

The client exits the app (close browser window), which means the SSE event handler will sit idle until the next event to be emittted, at which point it will get a error.BrokenPipe when attempting to write to the connection.

karlseguin commented 1 year ago

Thanks, I added ConnectionResetByPeer