http2: remove `waitTrailers` listener after closing a stream
When writeHear
of Http2ServerResponse
instance are called with 204,
205 and 304 status codes an underlying stream closes.
If call end
method after sending any of these status codes it will
cause an error TypeError: Cannot read property 'Symbol(trailers)' of undefined
because a reference to Http2ServerResponse
instance
associated with Http2Stream already was deleted.
The closing of stream causes emitting watiTrailers
event and, when
this event handles inside onStreamTrailerReady
handler, there is
no reference to Http2ServerResponse instance.
Fises: https://github.com/nodejs/node/issues/21740
Checklist
-
make -j4 test
(UNIX), orvcbuild test
(Windows) passes -
tests and/or benchmarks are included -
commit message follows commit guidelines
After applying this changes trailing headers won't be sent if 204/205 and 204 status has been sent. However, I don't think It is a problem, as according to standard for this HTTP status codes server shouldn't generate payload and have to close a connection after sending the blank line terminating the header section.
204 - https://tools.ietf.org/html/rfc7231#section-6.3.5 205 - https://tools.ietf.org/html/rfc7231#section-6.3.6 304 - https://tools.ietf.org/html/rfc7232#section-4.1
Additional info: https://tools.ietf.org/html/rfc7230#section-3.3.3 (point 1) https://tools.ietf.org/html/rfc7540#section-8.1.2.4