forked from nodejs/node
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
async_hooks: use correct resource for AsyncLocalStorage
Fixes: nodejs#40693 Signed-off-by: Darshan Sen <darshan.sen@postman.com>
- Loading branch information
Showing
4 changed files
with
106 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const assert = require('assert'); | ||
const dgram = require('dgram'); | ||
const { AsyncLocalStorage } = require('async_hooks'); | ||
|
||
dgram.createSocket('udp4') | ||
.on('message', function(msg, rinfo) { this.send(msg, rinfo.port); }) | ||
.on('listening', function() { | ||
const asyncLocalStorage = new AsyncLocalStorage(); | ||
const store = { val: 'abcd' }; | ||
asyncLocalStorage.run(store, () => { | ||
const client = dgram.createSocket('udp4'); | ||
client.on('message', (msg, rinfo) => { | ||
assert.deepStrictEqual(asyncLocalStorage.getStore(), store); | ||
client.close(); | ||
this.close(); | ||
}); | ||
client.send('Hello, world!', this.address().port); | ||
}); | ||
}) | ||
.bind(0); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
'use strict'; | ||
|
||
require('../common'); | ||
|
||
const assert = require('assert'); | ||
const net = require('net'); | ||
const { AsyncLocalStorage } = require('async_hooks'); | ||
|
||
net | ||
.createServer((socket) => { | ||
socket.write('Hello, world!'); | ||
socket.pipe(socket); | ||
}) | ||
.listen(0, function() { | ||
const asyncLocalStorage = new AsyncLocalStorage(); | ||
const store = { val: 'abcd' }; | ||
asyncLocalStorage.run({ val: 'abcd' }, () => { | ||
const client = net.connect({ port: this.address().port }); | ||
client.on('data', () => { | ||
assert.deepStrictEqual(asyncLocalStorage.getStore(), store); | ||
client.end(); | ||
this.close(); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
|
||
const assert = require('assert'); | ||
const fixtures = require('../common/fixtures'); | ||
const tls = require('tls'); | ||
const { AsyncLocalStorage } = require('async_hooks'); | ||
|
||
const options = { | ||
cert: fixtures.readKey('rsa_cert.crt'), | ||
key: fixtures.readKey('rsa_private.pem'), | ||
rejectUnauthorized: false | ||
}; | ||
|
||
tls | ||
.createServer(options, (socket) => { | ||
socket.write('Hello, world!'); | ||
socket.pipe(socket); | ||
}) | ||
.listen(0, function() { | ||
const asyncLocalStorage = new AsyncLocalStorage(); | ||
const store = { val: 'abcd' }; | ||
asyncLocalStorage.run({ val: 'abcd' }, () => { | ||
const client = tls.connect({ port: this.address().port, ...options }); | ||
client.on('data', () => { | ||
assert.deepStrictEqual(asyncLocalStorage.getStore(), store); | ||
client.end(); | ||
this.close(); | ||
}); | ||
}); | ||
}); |