simplex-software / log_collection

log collection exercise
0 stars 0 forks source link

fs.open error after varied number of requests #1

Open bieron opened 3 years ago

bieron commented 3 years ago

Hello Maximiliano. Thanks for taking on the assignment!

/tmp/kk/log_collection nvm use v16.8.0
Now using node v16.8.0 (npm v7.21.0)
/tmp/kk/log_collection npm i

added 420 packages, and audited 421 packages in 2s

33 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
/tmp/kk/log_collection npm run build

> log-collection@1.0.0 build
> rimraf dist && tsc

/tmp/kk/log_collection npm start

> log-collection@1.0.0 start
> node dist/src/index.js

after 3-4 of requests to /events?file=apt/history.log:

node:internal/validators:87
        throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
        ^

TypeError [ERR_INVALID_ARG_TYPE]: The "fd" argument must be of type number. Received null
    at Object.read (node:fs:604:8)
    at LogReadable._read (/tmp/kk/log_collection/dist/src/controllers/LogRedable.js:46:12)
    at LogReadable.Readable.read (node:internal/streams/readable:487:10)
    at maybeReadMore_ (node:internal/streams/readable:638:12)
    at processTicksAndRejections (node:internal/process/task_queues:83:21) {
  code: 'ERR_INVALID_ARG_TYPE'
}

Does not have to be apt/history.log, I can reproduce it with any valid file, after 2-4 requests.

fbonecco-cribl commented 3 years ago

Hi Maximiliano, this is Franco from Cribl. I'm seeing the same issue JB reported earlier but, in my case, it fails on the first requests:

> log-collection@1.0.0 start /home/goat/workspace/interviews/log_collection
> node dist/src/index.js

internal/validators.js:92
        throw new ERR_INVALID_ARG_TYPE(name, 'number', value);
        ^

TypeError [ERR_INVALID_ARG_TYPE]: The "fd" argument must be of type number. Received null
    at Object.read (fs.js:485:3)
    at LogReadable._read (/home/goat/workspace/interviews/log_collection/dist/src/controllers/LogRedable.js:44:12)
    at LogReadable.Readable.read (_stream_readable.js:481:10)
    at resume_ (_stream_readable.js:968:12)
    at processTicksAndRejections (internal/process/task_queues.js:80:21) {
  code: 'ERR_INVALID_ARG_TYPE'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! log-collection@1.0.0 start: `node dist/src/index.js`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the log-collection@1.0.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/goat/.npm/_logs/2021-09-01T12_24_40_943Z-debug.log

Node version: 14.15.1

maxiplano commented 3 years ago

This issue was due to a race condition on the construction of LogReadable. fd may not be assign when _read is call. More recent master version ( after commit 3a94521380eb656e98507427c2be672d463dd92f ) implements LogReadable using fs/promises instead of callbacks, removing this issue.