Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FATAL ERROR if filehandle.close() is called after fd is closed by createReadStream #31202

Closed
kevinjohna6 opened this issue Jan 6, 2020 · 1 comment
Labels
fs Issues and PRs related to the fs subsystem / file system.

Comments

@kevinjohna6
Copy link

  • Version: v13.5.0
  • Platform: Linux 4.4.0-170-generic Ubuntu SMP Thu Nov 14 01:45:04 UTC 2019 x86_64 GNU/Linux
  • Subsystem: fs

Node will abort if filehandle.close() is called after fd is closed by createReadStream.
I am unsure if this "FATAL ERROR" is considered a bug or is expected behavior.
I expected a javascript rejection from fh.close().

stacktrace:

FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope
 1: 0x9f28f0 node::Abort() [node]
 2: 0x9f4bb2 node::OnFatalError(char const*, char const*) [node]
 3: 0xb5a02a v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: 0xcd291a v8::internal::HandleScope::Extend(v8::internal::Isolate*) [node]
 5: 0xcf288c v8::internal::Factory::NewRawOneByteString(int, v8::internal::AllocationType) [node]
 6: 0xcf22de v8::internal::Factory::NewStringFromOneByte(v8::internal::Vector<unsigned char const> const&, v8::internal::AllocationType) [node]
 7: 0xb72612 v8::String::NewFromOneByte(v8::Isolate*, unsigned char const*, v8::NewStringType, int) [node]
 8: 0x967d55 node::UVException(v8::Isolate*, int, char const*, char const*, char const*, char const*) [node]
 9: 0x9f6969  [node]
10: 0x1318a45  [node]
11: 0x131cf31  [node]
12: 0x132f7d8  [node]
13: 0x131d8bb uv_run [node]
14: 0xa2fca3 node::NodeMainInstance::Run() [node]
15: 0x9c4511 node::Start(int, char**) [node]
16: 0x7fd1490e6830 __libc_start_main [/lib/x86_64-linux-gnu/libc.so.6]
17: 0x960ea5  [node]
const fs = require("fs");
async function main() {
	const fpath = "./test.txt";	
	const fh = await fs.promises.open(fpath);
	
	const fstream = fs.createReadStream(fpath, {
		fd: fh.fd,
		//autoClose: false, //!!!!prevents the abort
	});

	fstream.on("end", () => {
		fh.close().catch(e => console.error(e)); //node aborts and does not execute javascript catch
	});
	fstream.pipe(process.stdout);
}

main().catch(e => console.error(e));
@gireeshpunathil
Copy link
Member

looks like non-promisified variant works as expected:

const fs = require('fs')
const file = './test.txt'
fs.open(file, (err, fd) => {
  const str = fs.createReadStream(file, {fd: fd})
  str.on('end', () => {
    fs.close(fd, (err) => {console.log(err)})
  })
  str.pipe(process.stdout)
})
[Error: EBADF: bad file descriptor, close] {
  errno: -9,
  code: 'EBADF',
  syscall: 'close'
}

@addaleax addaleax added the fs Issues and PRs related to the fs subsystem / file system. label Jan 9, 2020
addaleax added a commit to addaleax/node that referenced this issue Jan 9, 2020
@Trott Trott closed this as completed in 679eb3e Jan 11, 2020
MylesBorins pushed a commit that referenced this issue Jan 16, 2020
Fixes: #31202

PR-URL: #31276
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
codebytere pushed a commit that referenced this issue Mar 14, 2020
Fixes: #31202

PR-URL: #31276
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
codebytere pushed a commit that referenced this issue Mar 17, 2020
Fixes: #31202

PR-URL: #31276
Reviewed-By: David Carlier <devnexen@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fs Issues and PRs related to the fs subsystem / file system.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants