node-clinic
node-clinic copied to clipboard
bug: Analysing dataError: ENOENT: no such file or directory [...]<pid>.clinic-doctor-processstat
Hi 👋
Here I bug I faced today. I'm obviously available to help 🤚. Didn't have time to debug yet. If you have any insights feel free to share it ^^
Expected Behavior
A *.clinic-doctor-processstat
file should be generated.
Current Behavior
The doctor command doesn't work due to this file missing.
Steps to Reproduce (for bugs)
- Use this
fail.js
script:
#!/usr/bin/env node
const async = require('async');
const shell = require('shelljs');
module.exports = function (exit) {
async.waterfall([
function (next) {
next();
},
function (next) {
next();
}
], exit);
};
!module.parent && module.exports(shell.exit);
- Run
clinic doctor -- node fail.js
- Got this error:
Analysing dataError: ENOENT: no such file or directory, open '.clinic/7063.clinic-doctor/7063.clinic-doctor-processstat'
Sample upload
![Screenshot 2022-02-07 at 17 06 58](https://user-images.githubusercontent.com/22824417/152827108-272a2e01-35aa-4c89-b760-8e8ce0e21101.png)
Environment
- Clinic.js version:
v11.0.0
- Doctor version=
v9.2.1
- Node.js version:
v17.4.0
- Npm:
v8.3.1
- Browser name and version: Firefox 96.0.3
- Operating system and version: OSX 12.1.0
Could you share the script code or at least a reproducible example?
Yeah, @RafaelGSS ^^ Updated!
@tony-go did you get it fixed ?
@tony-go did you get it fixed ?
Nope, sorry :/
Hi! I'm working to debug the problem. If anyone has found anything yet please let me know.
Hi again!
The problem seems to be that those functions are running and exiting before the setTimeout callback that schedules processstat
writes is triggered.
Making any of the functions go over a setTimeout
or nextTick
would resolve the issue.
Anyway if we want to support this case of functions running synchronously IMHO the easiest way forward is to initialise the file empty as it is currently being done with the other files. I can make a PR in node-clinic-doctor for that if that would be the desired approach. WDYT @RafaelGSS @simoneb?
Thanks @Ceres6 , I'm not really sure about the solution here, but I'd like to understand the problem better. Is there a generalization we can do of this issue? Meaning, if we profile a program which does nothing, is this the behavior we obtain?
Basically, the script is forcing the exit by shell.exit
so, I don't see it as a bug but as an expected condition.
If you just remove the shell.exit it should work.
Perhaps mention it in the docs + in the error message.
So add a try-catch when reading the processstat file, and when ENOENT, update the message to: "the program exited before the clinic background tasks, please do not call process.exit manually".
That's right either removing the forced exit or having the program do something or be an ESM solves the issue. I'll go with the docs + error message then. Thanks @RafaelGSS