-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
node:http server doesn't handle read errors #22820
Comments
@ianbrault do you know, by the way, if there's any way to catch this exception on a global level to prevent server restart? |
@punarinta I am not aware if there's a way to catch this but perhaps someone with more knowledge on the matter can chime in |
Thank you! |
@ianbrault, thanks for opening the issue. I created an example to reproduce the bug but it resulted in a different error. Is it possible for you to share an example that reproduces the error that you mentioned? Example: import express from 'express';
const app = express();
app.get("/", (_req, res) => {
console.info("GET /");
res.sendFile("home.html", {
root: import.meta.dirname,
});
});
const port = 3000;
app.listen(port, () => {
console.log(`Server listening on port ${port}`);
}); The error I encountered is the following which is triggered after
|
From @lucacasonato the issue should be fixable by wrapping |
@satyarohith I have not been able to reproduce using import express from "npm:[email protected]";
import mongoose from "npm:mongoose@^6.7";
import * as path from "$std/path/mod.ts";
function getViewsDirectory(app: string): string {
const filePath = path.fromFileUrl(import.meta.url);
const dirPath = path.dirname(filePath)
return path.join(dirPath, app, "views");
}
const router = express.Router();
router.get("/", (_req, res) => {
info("GET /");
res.sendFile("home.html", {
root: path.getViewsDirectory("home")
});
});
const app = express();
app.use(express.json());
app.use(express.urlencoded({extended: true}));
app.use(router);
await mongoose.connect("mongodb://localhost:27017");
const port = 3030;
app.listen(port, () => console.log(`server running on https://127.0.0.1:${port}`)); |
I got here from #15203, I have similar problem with server sent events. import express from "express";
const app = express();
app.get('/sse', async (req, res) => {
res.header('Content-Type', 'text/event-stream')
req.once('close', () => {
if (req.aborted) {
console.log('request closed')
}
})
while(true) {
res.write('data: hello\n\n')
await new Promise(resolve => setTimeout(resolve, 1000))
}
});
app.listen(8000, () => console.log('Server listening on port 8000')) After closing connection "request closed" should be displayed (this works in node)
|
Version: Deno 1.40.3
Hit the following exception while my webserver was running:
The server is using express on top of Deno:
and the home route does nothing outside of sending a file:
I am suspicious that the exception is due to the 4 requests within the same second.
The text was updated successfully, but these errors were encountered: