mirror of
https://github.com/nodejs/node.git
synced 2026-11-25 23:01:06 -05:00
net,tls: add abort signal support to connect
Add documentation for net.connect AbortSignal, and add the support to tls.connect as well PR-URL: https://github.com/nodejs/node/pull/37735 Reviewed-By: Benjamin Gruenbaum <benjamingr@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
This commit is contained in:
1 parent
8792c7c96b
commit
669b81c68b
7 files changed
+388
No files matched your search
@@ -14,6 +14,7 @@ const options = {
|
||||
cert: fixtures.readKey('agent1-cert.pem')
|
||||
};
|
||||
|
||||
// Check async post-aborted
|
||||
(async () => {
|
||||
const { port, server } = await new Promise((resolve) => {
|
||||
const server = https.createServer(options, () => {});
|
||||
@@ -38,3 +39,57 @@ const options = {
|
||||
server.close();
|
||||
}
|
||||
})().then(common.mustCall());
|
||||
|
||||
// Check sync post-aborted signal
|
||||
(async () => {
|
||||
const { port, server } = await new Promise((resolve) => {
|
||||
const server = https.createServer(options, () => {});
|
||||
server.listen(0, () => resolve({ port: server.address().port, server }));
|
||||
});
|
||||
try {
|
||||
const ac = new AbortController();
|
||||
const { signal } = ac;
|
||||
const req = https.request({
|
||||
host: 'localhost',
|
||||
port,
|
||||
path: '/',
|
||||
method: 'GET',
|
||||
rejectUnauthorized: false,
|
||||
signal,
|
||||
});
|
||||
assert.strictEqual(getEventListeners(ac.signal, 'abort').length, 1);
|
||||
ac.abort();
|
||||
const [ err ] = await once(req, 'error');
|
||||
assert.strictEqual(err.name, 'AbortError');
|
||||
assert.strictEqual(err.code, 'ABORT_ERR');
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
})().then(common.mustCall());
|
||||
|
||||
// Check pre-aborted signal
|
||||
(async () => {
|
||||
const { port, server } = await new Promise((resolve) => {
|
||||
const server = https.createServer(options, () => {});
|
||||
server.listen(0, () => resolve({ port: server.address().port, server }));
|
||||
});
|
||||
try {
|
||||
const ac = new AbortController();
|
||||
const { signal } = ac;
|
||||
ac.abort();
|
||||
const req = https.request({
|
||||
host: 'localhost',
|
||||
port,
|
||||
path: '/',
|
||||
method: 'GET',
|
||||
rejectUnauthorized: false,
|
||||
signal,
|
||||
});
|
||||
assert.strictEqual(getEventListeners(ac.signal, 'abort').length, 0);
|
||||
const [ err ] = await once(req, 'error');
|
||||
assert.strictEqual(err.name, 'AbortError');
|
||||
assert.strictEqual(err.code, 'ABORT_ERR');
|
||||
} finally {
|
||||
server.close();
|
||||
}
|
||||
})().then(common.mustCall());
|
||||
Reference in new issue
Block a user