node-clinic icon indicating copy to clipboard operation
node-clinic copied to clipboard

bug: Analysing dataError: ENOENT: no such file or directory [...]<pid>.clinic-doctor-processstat

Open tony-go opened this issue 2 years ago • 2 comments

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)

  1. Use this fail.jsscript:
#!/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);
  1. Run clinic doctor -- node fail.js
  2. 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

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

tony-go avatar Feb 07 '22 16:02 tony-go

Could you share the script code or at least a reproducible example?

RafaelGSS avatar Feb 07 '22 17:02 RafaelGSS

Yeah, @RafaelGSS ^^ Updated!

tony-go avatar Feb 08 '22 08:02 tony-go

@tony-go did you get it fixed ?

vamshi9666 avatar Jan 09 '23 05:01 vamshi9666

@tony-go did you get it fixed ?

Nope, sorry :/

tony-go avatar Jan 09 '23 10:01 tony-go

Hi! I'm working to debug the problem. If anyone has found anything yet please let me know.

Ceres6 avatar Jan 09 '23 15:01 Ceres6

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?

Ceres6 avatar Jan 11 '23 17:01 Ceres6

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?

simoneb avatar Jan 11 '23 17:01 simoneb

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.

RafaelGSS avatar Jan 11 '23 17:01 RafaelGSS

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".

RafaelGSS avatar Jan 11 '23 17:01 RafaelGSS

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

Ceres6 avatar Jan 11 '23 17:01 Ceres6