http: fix drain event with cork/uncork in ServerResponse
Closed
TH
1y ago+77+77+01234567890123456789-1-1-0123456789
Fixes #60432
When using cork() and uncork() with ServerResponse, the drain event was not reliably emitted after uncorking. This occurred because the uncork() method did not check if a drain was pending (kNeedDrain flag) after flushing the chunked buffer.
The Problem:
- When corked,
write()buffers data inkChunkedBufferinstead of sending immediately - If
write()returnsfalse,kNeedDrainis set totrue - When
uncork()is called, it flushes the buffer by calling_send() - After flushing,
uncork()never checked if drain was needed or emitted the event - This left the response waiting for a
drainevent that would never fire
The Fix:
This commit ensures that when uncork() successfully flushes buffered data and a drain was needed, the drain event is emitted immediately.
Changes:
- Modified
OutgoingMessage.prototype.uncork()inlib/_http_outgoing.js - Capture return value from final
_send()call - Check if drain was pending after successful flush
- Emit
drainevent when appropriate
Testing:
The issue could be reproduced by using cork() with multiple large writes and checking for drain events. With this fix, the drain event now fires correctly after uncork().