-
Notifications
You must be signed in to change notification settings - Fork 285
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
EAGAIN returned by fs.read #2663
Comments
If the file descriptor that you pass to |
Thanks for the answer. How is it possible in node to make a file descriptor non blocking. The filedescriptor is 0 i.e. stdin and it is connected to the terminal. Since I do not change the file descriptor mode, it should be blocking and the program should perform as my code snippet above. However this command fails immediately with node my_program while node my_program <some_file does its job without The only job of the program is to read something from stdin, process it and return the output to stdout. There is another strange thing I observed. If I hack the file descriptor and explicitly put |
Node controls fd 0-2. I.e., your script can read from or write to them directly. Use e.g. W.r.t. your examples: node decides based on the type of the stdio file descriptor whether to put it in non-blocking mode or not and how to read from it. When stdin is an on-disk file, it uses |
I still do not understand whats going on here. The main question: Why is the file descriptor A have read and reread the node documentation for Initially Clearly, nobody can help me to find the part of my code which accidentially has put If I'm using the wrong interface, I certainly can switch to the stream based interface. But since Since I want to use node very heavily, it is important for me to understand correctly the semantics of basic functions like Thanks for any hints
|
Sorry if I wasn't clear: node puts it in non-blocking mode in order that The difference you observe with different types of stdin is due to the fact that tty file descriptors integrate with
|
Thanks Ben for the comment. Now I begin to understand, what's going on here. The only remaining question: What is the condition for node putting For me it seems to be sporadic. In the code snippet in const fs = require('fs')
const buffer = Buffer.alloc (200)
fs.read (0, buffer, 0, 200, null, (err,nbytes,buffer) => {
console.log (nbytes + ' bytes read')
}) The command Do you have any idea what could be the difference? Thanks. |
Anything accessing stdio through the "ordained" APIs can put it in non-blocking mode. In theory a |
Under what circumstances can
fs.read(....)
call the callback with the error codeEAGAIN
. I was thinking this can never be the case, becausefs.read
is asynchronous i.e. non blocking.If I try the following code snippet (reading from stdin)
it works fine.
But I have the same code embedded in some more complex setting (the javascript code is generated by
js_of_ocaml
), I get under some circumstances an error withEAGAIN
when reading fromstdin
i.e.0
which is connected to a terminal.Am I missing some important details, because from my understanding, this behaviour should never happen.
The text was updated successfully, but these errors were encountered: