1'use strict'; 2const common = require('../common'); 3 4if (!common.hasCrypto) 5 common.skip('missing crypto'); 6 7const assert = require('assert'); 8const net = require('net'); 9const tls = require('tls'); 10 11const server = net.createServer(common.mustCall((c) => { 12 c.destroy(); 13})).listen(0, common.mustCall(() => { 14 const c = tls.connect({ port: server.address().port }); 15 c.on('error', () => { 16 // Otherwise `.write()` callback won't be invoked. 17 c._undestroy(); 18 }); 19 20 c.write('hello', common.mustCall((err) => { 21 assert.strictEqual(err.code, 'ECANCELED'); 22 server.close(); 23 })); 24})); 25