11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ciconst common = require('../common'); 41cb0ef41Sopenharmony_ciif (!common.hasCrypto) 51cb0ef41Sopenharmony_ci common.skip('missing crypto'); 61cb0ef41Sopenharmony_ci 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst tls = require('tls'); 91cb0ef41Sopenharmony_ciconst net = require('net'); 101cb0ef41Sopenharmony_ciconst { fork } = require('child_process'); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 131cb0ef41Sopenharmony_ci 141cb0ef41Sopenharmony_ci// Run in a child process because the PIPE file descriptor stays open until 151cb0ef41Sopenharmony_ci// Node.js completes, blocking the tmpdir and preventing cleanup. 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ciif (process.argv[2] !== 'child') { 181cb0ef41Sopenharmony_ci // Parent 191cb0ef41Sopenharmony_ci tmpdir.refresh(); 201cb0ef41Sopenharmony_ci 211cb0ef41Sopenharmony_ci // Run test 221cb0ef41Sopenharmony_ci const child = fork(__filename, ['child'], { stdio: 'inherit' }); 231cb0ef41Sopenharmony_ci child.on('exit', common.mustCall(function(code) { 241cb0ef41Sopenharmony_ci assert.strictEqual(code, 0); 251cb0ef41Sopenharmony_ci })); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ci return; 281cb0ef41Sopenharmony_ci} 291cb0ef41Sopenharmony_ci 301cb0ef41Sopenharmony_ci// Child 311cb0ef41Sopenharmony_ciconst server = net.createServer((c) => { 321cb0ef41Sopenharmony_ci c.end(); 331cb0ef41Sopenharmony_ci}).listen(common.PIPE, common.mustCall(() => { 341cb0ef41Sopenharmony_ci let errored = false; 351cb0ef41Sopenharmony_ci tls.connect({ path: common.PIPE }) 361cb0ef41Sopenharmony_ci .once('error', common.mustCall((e) => { 371cb0ef41Sopenharmony_ci assert.strictEqual(e.code, 'ECONNRESET'); 381cb0ef41Sopenharmony_ci assert.strictEqual(e.path, common.PIPE); 391cb0ef41Sopenharmony_ci assert.strictEqual(e.port, undefined); 401cb0ef41Sopenharmony_ci assert.strictEqual(e.host, undefined); 411cb0ef41Sopenharmony_ci assert.strictEqual(e.localAddress, undefined); 421cb0ef41Sopenharmony_ci server.close(); 431cb0ef41Sopenharmony_ci errored = true; 441cb0ef41Sopenharmony_ci })) 451cb0ef41Sopenharmony_ci .on('close', common.mustCall(() => { 461cb0ef41Sopenharmony_ci assert.strictEqual(errored, true); 471cb0ef41Sopenharmony_ci })); 481cb0ef41Sopenharmony_ci})); 49