Closed seriousme closed 1 year ago
Hi!
🙏 for reporting. This does seem like a bug on our end!
In case this might help: having a similar issue in https://stackblitz.com/github/Rest-Hooks/todo-example
Any progress on tracking this down?
@seriousme @ntucker We are starting to look into this issue now, but I can't offer a concrete timeline.
I'm curious if the problem is finding a solution or the cause? I ask because clearly there are situations where this does work, so I'm wondering how those frameworks work around this. Is this a problem with webpack-dev-server - and using the middleware or turning off watch mode or something might help?
I just checked: the problem seems to be in the logger:
This works: https://stackblitz.com/edit/http-server-hty4sx
With the only difference with the original being the removal of: { logger: true }
from line 2.
The logger is Pino, so the problem can be reduced to (and reproduced by):
const logger = require('pino')();
logger.info('hello world');
const child = logger.child({ a: 'property' });
child.info('hello child!');
Running this code in stackblitz gives the exact same error as the original Blitz:
~/projects/http-server-hty4sx
❯ node testpino.js
[Error: EBADF: bad file descriptor, write] {
syscall: 'write',
errno: -9,
code: 'EBADF'
}
Hope this helps.
Did some more digging:
Pino uses sonic-boom
to write logs, and that seems to be the source of the issue as:
const SonicBoom = require('sonic-boom');
const sonic = new SonicBoom({ fd: process.stdout.fd }); // or { dest: '/path/to/destination' }
sonic.write('hello sonic\n');
gives the exact same error:
❯ node testSonic.js
[EBADF: bad file descriptor, write] {
code: 'EBADF',
errno: -9,
path: undefined,
syscall: 'write'
}
Hope this helps.
And digging deeper :-)
This code:
const fs= require("fs");
fs.write(1, 'hello sonic\n', 'utf8', (err, n) => {
console.log({ err, n });
});
Returns on Linux:
$ node testSonic2.js
hello sonic
{ err: null, n: 12 }
But on Stackblitz:
❯ node testSonic2.js
{
err: [EBADF: bad file descriptor, write] {
code: 'EBADF',
errno: -9,
path: undefined,
syscall: 'write'
},
n: 0
}
This is where it ends for me and where the StackBlitz experts need to take over ;-) Workaround is of course to log to file instead ;-)
@seriousme Thanks a lot for digging in and creating a minimal reproduction. I can confirm that this currently doesn't work. Created a project here https://stackblitz.com/edit/node-2wyyde?file=index.js.
This was fixed a while ago and just confirmed that the fastify server now works 🎉 .
name: Bug report about: Create a report to help us improve title: 'can't run fastify webserver [Error: EBADF: bad file descriptor, write] ' labels: '' assignees: ''
Describe the bug can't run the fastify webserver
Link to the blitz that caused the error https://stackblitz.com/edit/http-server-r8kujv
To Reproduce Steps to reproduce the behavior:
Expected behavior nodemon will start the script, fastify webserver should start at port 3000
Version of webcontainer Hash: 7286dbe8d47d3473cde7be488b7d048fb59b05f2
Screenshots If applicable, add screenshots to help explain your problem.
Desktop (please complete the following information): Browser name = Chrome Full version = 90.0.4430.218 Major version = 90 navigator.appName = Netscape navigator.userAgent = Mozilla/5.0 (X11; CrOS x86_64 13816.82.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/90.0.4430.218 Safari/537.36 performance.memory = { totalJSHeapSize: 53915145, usedJSHeapSize: 52589837, jsHeapSizeLimit: 2020868096 }
Additional context I know fastify is rather low level node.js, but if this works almost anything will work ;-)