h2lean 0.10.1 → 0.10.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/stream.js +36 -1
- package/package.json +1 -1
package/lib/stream.js
CHANGED
|
@@ -195,6 +195,13 @@ function finishNT(stream) {
|
|
|
195
195
|
// They were already going to run in the same tick drain, so folding them into
|
|
196
196
|
// one callback only removes one TickObject per request.
|
|
197
197
|
function emitEndCloseNT(target) {
|
|
198
|
+
if (target._finishFuse) {
|
|
199
|
+
// the finish work rides here, ahead of every state this tick flips: the separate
|
|
200
|
+
// tick it replaces ran in the same drain, directly before this callback, when the
|
|
201
|
+
// session reference and _closeDelivered were still what end() left them.
|
|
202
|
+
target._finishFuse = false;
|
|
203
|
+
finishNT(target);
|
|
204
|
+
}
|
|
198
205
|
target._closeDelivered = true;
|
|
199
206
|
// node clears the stream's session reference in _destroy, before any of the close
|
|
200
207
|
// events go out (internal/http2/core.js:2546) -- see _closeNow for why the drop waits
|
|
@@ -211,6 +218,10 @@ function emitEndCloseNT(target) {
|
|
|
211
218
|
// in one turn, with no 'end' owed. Marks the node-equivalent close moment -- see
|
|
212
219
|
// _closeDelivered above.
|
|
213
220
|
function emitCloseDeliveredNT(target) {
|
|
221
|
+
if (target._finishFuse) {
|
|
222
|
+
target._finishFuse = false;
|
|
223
|
+
finishNT(target);
|
|
224
|
+
}
|
|
214
225
|
target._closeDelivered = true;
|
|
215
226
|
target.session = undefined;
|
|
216
227
|
target.emit('close');
|
|
@@ -454,6 +465,9 @@ class Http2Stream extends Stream {
|
|
|
454
465
|
// 'close' with writableFinished false and no 'finish').
|
|
455
466
|
this._writableFinished = false;
|
|
456
467
|
this._finishQueued = false;
|
|
468
|
+
// The finish work carried into a close-delivery tick scheduled by the same call
|
|
469
|
+
// of _endLocalSide (see the fuse there) instead of a nextTick of its own.
|
|
470
|
+
this._finishFuse = false;
|
|
457
471
|
}
|
|
458
472
|
|
|
459
473
|
get destroyed() {
|
|
@@ -2427,7 +2441,19 @@ class Http2Stream extends Stream {
|
|
|
2427
2441
|
if (this._queued === null) {
|
|
2428
2442
|
// every octet handed over has been accepted by the session: node's condition
|
|
2429
2443
|
// for the writable 'finish'
|
|
2430
|
-
this.
|
|
2444
|
+
if (!this._waitForTrailers && this._state.remoteClose === 1 && !this._destroyed) {
|
|
2445
|
+
// The graceful close below schedules a close-delivery tick in this same call,
|
|
2446
|
+
// and finishNT would have run in the same tick drain directly before it: the
|
|
2447
|
+
// finish work rides at the head of that tick instead of paying one of its own.
|
|
2448
|
+
// Measured (item 45): the tick of its own is ~0.05 us/req on the GET/empty-
|
|
2449
|
+
// response shape and the fuse recovers ~0.03 of it; what is left is the flag
|
|
2450
|
+
// flip and the emit, which the unpatched shape paid too. The trailers and
|
|
2451
|
+
// auto-close shapes keep their own tick: there the ordering against
|
|
2452
|
+
// 'wantTrailers'/autoCloseNT's setImmediate is what node pins.
|
|
2453
|
+
this._finishFuse = true;
|
|
2454
|
+
} else {
|
|
2455
|
+
this._scheduleFinish();
|
|
2456
|
+
}
|
|
2431
2457
|
}
|
|
2432
2458
|
if (this._state.state === ST_OPEN) {
|
|
2433
2459
|
this._state.state = ST_HALF_CLOSED_LOCAL;
|
|
@@ -2519,6 +2545,15 @@ class Http2Stream extends Stream {
|
|
|
2519
2545
|
if (this._destroyed) {
|
|
2520
2546
|
return;
|
|
2521
2547
|
}
|
|
2548
|
+
if (this._finishFuse) {
|
|
2549
|
+
// The end() in this turn fused its finish into a close-delivery tick that this
|
|
2550
|
+
// destroy now replaces. The destroy is not the hot shape: hand the finish back the
|
|
2551
|
+
// separate tick it would have had, scheduled before the close ticks below -- the
|
|
2552
|
+
// position (and the post-destroy session view) finishNT had when it was always
|
|
2553
|
+
// scheduled from _endLocalSide.
|
|
2554
|
+
this._finishFuse = false;
|
|
2555
|
+
process.nextTick(finishNT, this);
|
|
2556
|
+
}
|
|
2522
2557
|
this._destroyed = true;
|
|
2523
2558
|
// node's destroy does not touch state.flowing — the readableFlowing getter keeps
|
|
2524
2559
|
// reporting the last resume()/pause()/listener verdict even after the destroy
|
package/package.json
CHANGED