Skip to content

[REG 16.6->16.7] TCP/TLS drops AsyncLocalStorage #40693

Description

@orgads

Version

v16.13.0

Platform

Microsoft Windows NT 10.0.19043.0 x64

Subsystem

tcp/tls/async_hooks

What steps will reproduce the bug?

const { AsyncLocalStorage } = require('async_hooks');
const net = require('net');

const asyncLocalStorage = new AsyncLocalStorage();

asyncLocalStorage.run({val: 'abcd'}, () => {
  const socket = new net.Socket();
  socket.on('data', () => {
    // This is 'abcd' with Node 16.6.x, and undefined with Node >=16.7.0
    console.log(asyncLocalStorage.getStore()?.val);
  });
  socket.connect(80, 'google.com', function() {
    socket.write('GET /\n');
  });
});

TLS socket is also broken:

const { AsyncLocalStorage } = require('async_hooks');
const tls = require('tls');

const asyncLocalStorage = new AsyncLocalStorage();

asyncLocalStorage.run({val: 'abcd'}, () => {
  const socket = tls.connect({ host: 'google.com', port: 443 });
  socket.on('data', () => {
    // This is 'abcd' with Node 16.6.x, and undefined with Node >=16.7.0
    console.log(asyncLocalStorage.getStore()?.val);
    socket.end();
  });
  socket.on('error', console.error);
  socket.write('GET /\n');
});

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior?

It should write abcd.

What do you see instead?

undefined

Additional information

No response

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    async_hooksIssues and PRs related to the async hooks subsystem.confirmed-bugIssues and PRs for confirmed bugs.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions