11cb0ef41Sopenharmony_ci'use strict'; 21cb0ef41Sopenharmony_ci 31cb0ef41Sopenharmony_ci// Refs: https://github.com/nodejs/node/issues/34266 41cb0ef41Sopenharmony_ci// Failing to close a file should not keep the event loop open. 51cb0ef41Sopenharmony_ci 61cb0ef41Sopenharmony_ciconst common = require('../common'); 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ci 91cb0ef41Sopenharmony_ciconst fs = require('fs'); 101cb0ef41Sopenharmony_ci 111cb0ef41Sopenharmony_ciconst debuglog = (arg) => { 121cb0ef41Sopenharmony_ci console.log(new Date().toLocaleString(), arg); 131cb0ef41Sopenharmony_ci}; 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciconst tmpdir = require('../common/tmpdir'); 161cb0ef41Sopenharmony_citmpdir.refresh(); 171cb0ef41Sopenharmony_ci 181cb0ef41Sopenharmony_cilet openFd; 191cb0ef41Sopenharmony_ci 201cb0ef41Sopenharmony_cifs.open(`${tmpdir.path}/dummy`, 'wx+', common.mustCall((err, fd) => { 211cb0ef41Sopenharmony_ci debuglog('fs open() callback'); 221cb0ef41Sopenharmony_ci assert.ifError(err); 231cb0ef41Sopenharmony_ci openFd = fd; 241cb0ef41Sopenharmony_ci})); 251cb0ef41Sopenharmony_cidebuglog('waiting for callback'); 261cb0ef41Sopenharmony_ci 271cb0ef41Sopenharmony_ciprocess.on('beforeExit', common.mustCall(() => { 281cb0ef41Sopenharmony_ci if (openFd) { 291cb0ef41Sopenharmony_ci fs.closeSync(openFd); 301cb0ef41Sopenharmony_ci } 311cb0ef41Sopenharmony_ci})); 32