Skip to content

Commit 318fcf8

Browse files
ShogunPandacodebytere
authored andcommittedJun 7, 2020
doc: add note about clientError writable handling
PR-URL: #33308 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 30c9cb5 commit 318fcf8

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed
 

‎doc/api/http.md

+15
Original file line numberDiff line numberDiff line change
@@ -1003,6 +1003,21 @@ ensure the response is a properly formatted HTTP response message.
10031003
correctly;
10041004
* `rawPacket`: the raw packet of current request.
10051005

1006+
In some cases, the client has already received the response and/or the socket
1007+
has already been destroyed, like in case of `ECONNRESET` errors. Before
1008+
trying to send data to the socket, it is better to check that it is still
1009+
writable.
1010+
1011+
```js
1012+
server.on('clientError', (err, socket) => {
1013+
if (err.code === 'ECONNRESET' || !socket.writable) {
1014+
return;
1015+
}
1016+
1017+
socket.end('HTTP/1.1 400 Bad Request\r\n\r\n');
1018+
});
1019+
```
1020+
10061021
### Event: `'close'`
10071022
<!-- YAML
10081023
added: v0.1.4

0 commit comments

Comments
 (0)
Please sign in to comment.