help icon indicating copy to clipboard operation
help copied to clipboard

Does data event of net/tls/http/https/http2/... promise the buffer chunk byteOffset always be 0 (never from pool)?

Open LongTengDao opened this issue 3 years ago • 1 comments

Details

If not, user should always use chunk.byteOffset instead of 0, and copy it for long time chunk to avoid pool leak (the original ref will prevent the other part of chunk.buffer to release).

Node.js version

all

Example code

socket.on('data', chunk => {
if ( chunk.byteOffset===0 ) { return; } 
  use(
    new Uint8Array(
      chunk.buffer,
      chunk.byteOffset,// Can this simplify to 0 safely?
      1,
    )
  );
});

Operating system

all

Scope

runtime

Module and version

net tls http https http2 ...

LongTengDao avatar Aug 20 '22 16:08 LongTengDao

@bnoordhuis Would you help me? I'm a contributor of high-performance web server, I need to confirm this cautiously. And thank you for the relational help in issue #2584 .

LongTengDao avatar Aug 20 '22 16:08 LongTengDao