xref: /third_party/node/test/parallel/test-fs-filehandle-use-after-close.js (revision 1cb0ef41)
  • Home
  • History
  • Annotate Annotate
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
  • only in /third_party/node/test/parallel/
11cb0ef41Sopenharmony_ci'use strict';
21cb0ef41Sopenharmony_ciconst common = require('../common');
31cb0ef41Sopenharmony_ciconst assert = require('assert');
41cb0ef41Sopenharmony_ciconst fs = require('fs').promises;
51cb0ef41Sopenharmony_ci
61cb0ef41Sopenharmony_ci(async () => {
71cb0ef41Sopenharmony_ci  const filehandle = await fs.open(__filename);
81cb0ef41Sopenharmony_ci
91cb0ef41Sopenharmony_ci  assert.notStrictEqual(filehandle.fd, -1);
101cb0ef41Sopenharmony_ci  await filehandle.close();
111cb0ef41Sopenharmony_ci  assert.strictEqual(filehandle.fd, -1);
121cb0ef41Sopenharmony_ci
131cb0ef41Sopenharmony_ci  // Open another file handle first. This would typically receive the fd
141cb0ef41Sopenharmony_ci  // that `filehandle` previously used. In earlier versions of Node.js, the
151cb0ef41Sopenharmony_ci  // .stat() call would then succeed because it still used the original fd;
161cb0ef41Sopenharmony_ci  // See https://github.com/nodejs/node/issues/31361 for more details.
171cb0ef41Sopenharmony_ci  const otherFilehandle = await fs.open(process.execPath);
181cb0ef41Sopenharmony_ci
191cb0ef41Sopenharmony_ci  assert.rejects(() => filehandle.stat(), {
201cb0ef41Sopenharmony_ci    code: 'EBADF',
211cb0ef41Sopenharmony_ci    syscall: 'fstat'
221cb0ef41Sopenharmony_ci  });
231cb0ef41Sopenharmony_ci
241cb0ef41Sopenharmony_ci  await otherFilehandle.close();
251cb0ef41Sopenharmony_ci})().then(common.mustCall());
26

Indexes created Thu Nov 07 10:32:03 CST 2024