Unitech / Unitech/pm2

Error: EBADF: bad file descriptor, write

Open
#4,922 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

What's going wrong?

I have an express server application that handles a few NodeJS API and hosts the Angular 10 app. In production, I use process manager PM2. When the user visits https://domainname.com/webpage, the app crashes with the below error. PM2 restarts the application. To continue, the user has to refresh the webpage.

Error: EBADF: bad file descriptor, write
    at Socket._write (internal/net.js:54:25)
    at doWrite (_stream_writable.js:403:12)
    at writeOrBuffer (_stream_writable.js:387:5)
    at Socket.Writable.write (_stream_writable.js:318:11)
    at Array.logRequest (C:\NODE_APPS\website\node_modules\morgan\index.js:130:14)
    at listener (C:\NODE_APPS\website\node_modules\on-finished\index.js:169:15)
    at onFinish (C:\NODE_APPS\website\node_modules\on-finished\index.js:100:5)
    at callback (C:\NODE_APPS\website\node_modules\ee-first\index.js:55:10)
    at ServerResponse.onevent (C:\NODE_APPS\website\node_modules\ee-first\index.js:93:5)
    at ServerResponse.emit (events.js:327:22)
    at onFinish (_http_outgoing.js:723:10)
    at onCorkedFinish (_stream_writable.js:673:5)
    at afterWrite (_stream_writable.js:490:5)
    at afterWriteTick (_stream_writable.js:477:10)
    at processTicksAndRejections (internal/process/task_queues.js:83:21) {
       errno: 'EBADF',
       syscall: 'write',
      code: 'EBADF'
   }
GetRegValue(): Unable to RegOpenKeyEx () The system cannot find the file specified.

If I don't use process manager PM2 and run the application like node bin\www, everything works with no problem. It does randomly crashes with no error on the console. I am using an error handler called strong-error-handler. Application started using node bin\www crashes randomly but less frequently. Application started using PM2 crashes as soon as the user access the webpage. The PM2 logs mention about the morgan. I don't know what the error message means but I will really appreciate any assistance in the correct direction. Thank you!

How could we reproduce this issue?

N/A

Supporting information

$ pm2 report

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the crash with the Express application under PM2, comparing it with node bin\www, and collect the requested pm2 report and logs. Inspect the stack trace around morgan's request logging and determine what causes the bad file descriptor; done means identifying a reproducible cause and preventing the application from crashing.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, express, javascript, nodejs
Domain
backend, devops
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.