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

No events are emitted creating temporary file fails #45

Closed
selaux opened this issue Apr 18, 2021 · 4 comments · Fixed by #46
Closed

No events are emitted creating temporary file fails #45

selaux opened this issue Apr 18, 2021 · 4 comments · Fixed by #46
Labels
bug Something isn't working

Comments

@selaux
Copy link

selaux commented Apr 18, 2021

I am currently debugging weird behavior with graphql-upload where requests just get stuck indefinitely (not sure if I also need to open an issue there). I narrowed the issue down to the os.tmpdir() returned by Node not being present on the machine / in the docker image. In this case fs-capacitor does not seem to forward any information about this to the stream created by createReadStream and just silently not emitting any events at all. This also appies for any cases where fs.open fails, e.g. permission issues. Seems like with this behavior this error can never be handled (e.g. by graphql-upload). Is this intended behavor?


Reproduction:

  • Replace the SOME EXISTING FILE string in the example below with a path to an existing file
  • Run the example below using node sample.js: Events are emitted as expected.
  • Run the example below using TMPDIR=/tmp/definitely-does-not-exist sample.js: No events are emitted at all, Node just terminates.
import fs from "fs";
import os from "os";
import { WriteStream } from "fs-capacitor";

const capacitor = new WriteStream();
const source = fs.createReadStream("SOME EXISTING FILE", { encoding: "utf-8" });

source.pipe(capacitor);

const readStream = capacitor.createReadStream();

console.log("Tempdir", os.tmpdir());
readStream.on("error", (e) => console.error("Read Error", e));
readStream.on("data", (d) => console.log("Read Data", d.toString('utf-8')));
readStream.on("end", () => console.log("Read End"));
@selaux selaux changed the title No events are emitted when os.tmpdir is not writable No events are emitted creating tempfile fails Apr 18, 2021
@selaux selaux changed the title No events are emitted creating tempfile fails No events are emitted creating temporary file fails Apr 18, 2021
@mike-marcacci mike-marcacci added the bug Something isn't working label Apr 18, 2021
@mike-marcacci
Copy link
Owner

Hi @selaux, thanks for the excellent report and reproduction. However, can you check which version of fs-capacitor you have, and which version of node you're using?

When I attempt to reproduce this, I get:

❯❯❯ TMPDIR=/tmp/definitely-does-not-exist node sample.js
Tempdir /tmp/definitely-does-not-exist
node:events:306
      throw er; // Unhandled 'error' event
      ^

Error: ENOENT: no such file or directory, open 'SOME EXISTING FILE'
Emitted 'error' event on ReadStream instance at:
    at emitErrorNT (node:internal/streams/destroy:188:8)
    at emitErrorCloseNT (node:internal/streams/destroy:153:3)
    at processTicksAndRejections (node:internal/process/task_queues:80:21) {
  errno: -2,
  code: 'ENOENT',
  syscall: 'open',
  path: 'SOME EXISTING FILE'
}

@mike-marcacci
Copy link
Owner

Actually, scratch that - I see my error there 🤦🏼. Let me look again.

@mike-marcacci
Copy link
Owner

Excellent catch. Any failures from within initialization would have caused this hanging. Please see #46 which should resolve this. If this looks good to you, I'll merge release it as part of version 7 in May.

@selaux
Copy link
Author

selaux commented Apr 19, 2021

Looks good to me. Thanks for the quick response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants