h2lean 0.19.0 → 0.19.1

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.
@@ -19,6 +19,7 @@
19
19
  'use strict';
20
20
 
21
21
  const { EventEmitter } = require('node:events');
22
+ const net = require('node:net');
22
23
  const tls = require('node:tls');
23
24
  const f = require('../frames');
24
25
  const { Decoder, Encoder, HPackError, latin1, latin1Into } = require('../hpack');
@@ -1376,6 +1377,16 @@ class Http2ServerSession extends EventEmitter {
1376
1377
  // OPTIMIZATION.md item 69: this buys memory, not request-level time.
1377
1378
  this._pool = this._reuseBuffers
1378
1379
  ? (opts.stagingPool === undefined ? [] : opts.stagingPool) : null;
1380
+ // A net/TLS socket copies (or encrypts) the bytes at flush, so its write callback
1381
+ // is a real ownership boundary and a completed stage can be written into again.
1382
+ // A generic stream (stream.duplexPair, an accepted socket wrapped by the caller)
1383
+ // can push the very buffer we hand it to its peer and hold it until the peer
1384
+ // reads -- the callback then fires while the peer is still parsing, and a reused
1385
+ // stage would rewrite bytes already promised. Measured on a paused-duplexPair
1386
+ // server: 2 of 4 views were rewritten and the peer failed with ERR_HTTP2_ERROR
1387
+ // (frame larger than our advertised max frame size). Those sessions keep the old
1388
+ // allocate-per-batch path; TLSSocket is a net.Socket, so one check covers both.
1389
+ this._canPool = this._pool !== null && socket instanceof net.Socket;
1379
1390
  // _pending collects the full stage buffers of a batch; _returning is the batch
1380
1391
  // whose write callback is still owed, so only one list is in flight at a time.
1381
1392
  this._pending = [];
@@ -1661,7 +1672,7 @@ class Http2ServerSession extends EventEmitter {
1661
1672
  cap *= 2;
1662
1673
  }
1663
1674
  this._stageCap = Math.min(cap, MAX_OUT_BATCH);
1664
- const reused = this._pool === null ? undefined : this._pool.pop();
1675
+ const reused = !this._canPool ? undefined : this._pool.pop();
1665
1676
  this._stage = reused !== undefined && reused.length >= cap
1666
1677
  ? reused : Buffer.allocUnsafe(cap);
1667
1678
  }
@@ -1787,7 +1798,7 @@ class Http2ServerSession extends EventEmitter {
1787
1798
  // socket's no longer, so _need can write into one of them again.
1788
1799
  const done = this._returning;
1789
1800
  this._returning = null;
1790
- if (done !== null && this._pool !== null) {
1801
+ if (done !== null && this._canPool) {
1791
1802
  for (const b of done) {
1792
1803
  if (this._pool.length >= MAX_STAGE_POOL) {
1793
1804
  break;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "h2lean",
3
- "version": "0.19.0",
3
+ "version": "0.19.1",
4
4
  "description": "Pure-JavaScript HTTP/2 for Node.js — a drop-in node:http2 replacement (server and client, h2c and TLS) with zero dependencies",
5
5
  "main": "index.js",
6
6
  "files": [