http: only destroy socket once error is sent
This patch fixes the race condition: sometimes the socket is destroyed before the data is sent. If node is proxied by, for example, an AWS ELB, a 504 error would be returned instead of the expected 400.
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
documentation is changed or added -
commit message follows commit guidelines