expressjs / domain-middleware Goto Github PK
View Code? Open in Web Editor NEW`uncaughtException` middleware for connect, base on `domain` module.
License: Other
`uncaughtException` middleware for connect, base on `domain` module.
License: Other
@fengmk2 - you have been identified as the last / most active committer in this repo which is inactive for a while. This ping is to check with you to determine:
thanks!
I created something similar to this middleware, not sure how similar or different expressjs/domain-middleware is, but since this repo hasn't been touched in ~5 years maybe time for some freshness?
Is it the domain-middleware should only be used in development environment,not suppose to be used in production environment?
instead of try/catching server.close
and worker.disconnect
, we could listen to their close
and disconnect
signal and abstain from repeating if already closed / shut.
More elegant I think.
PR pending.
According to node documentation, calling worker.disconnect()
will close existing servers. And that's true (tested it) Calling worker.disconnect()
will even throw an uncaught if the servers are already closed (tested it also).
So the shutdown routine must be rewritten so that if in a worker, the midleware should only call worker.disconnect()
and not close the server directly.
PR pending.
For what I see in the code, if the call to server.close
fail, the cluster worker won't be disconnected.
This could be made stronger.
For what I can see in the code, the current code won't attempt to close the server when not in a cluster.
This is questionable (though I can think of some debatable reasons)
Being in an undefined state should call for an immediate stop to serving potentially wrong requests.
var http = require('http');
var connect = require('connect');
var domainMiddleware = require('domain-middleware');
var server = http.createServer();
var app = connect()
.use(
domainMiddleware({
server: server,
killTimeout: 30000,
}),
)
.use(function (req, res) {
// most handling logic is async in the real world
async function f(res){
if (Math.random() > 0.5) {
throw new Error('Asynchronous error from timeout');
} else {
res.end('Hello from Connect!');
}
}
f(); // this is not caught
})
.use(function (err, req, res, next) {
res.end(err.message);
});
server.on('request', app);
server.listen(1984);
This would allow :
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.