Conversation
/proc/* files could not be read, because fs.stat was returning 0 size. With new getSize function, their size information is correct, so they can now be read.
dougwilson
left a comment
There was a problem hiding this comment.
A general comment is that it seems when stat reads the file size as zero, this new code will read the entire contents of the file in to memory. If that is necessary, there should be some kind of upper limit on it so it does not cause the web server to oom on a file. You probably can just track the read chunk lengths without sorting a complete buffere to get the length of.
| } | ||
| } while (bytesRead !== 0); | ||
| fs.closeSync(fd); | ||
| return buf.toString('utf8', 0, pos).length; |
There was a problem hiding this comment.
This will return the wrong size if the data contains any utf8 charachers, as the length is the number of characters in this line, but what is needed is the number of bytes.
| let buf = tmpBuf; | ||
| let length = buf.length; | ||
| do { | ||
| bytesRead = fs.readSync(fd, buf, pos, buf.length - pos, null); |
There was a problem hiding this comment.
Performing sync operations will halt processing of parallel requests of the http server. You will need to use the async version of the functions, not the sync versions.
/proc/* files could not be read, because fs.stat was returning 0 size. With new getSize function, their size information is correct, so they can now be read.