domain-middleware icon indicating copy to clipboard operation
domain-middleware copied to clipboard

Domain does not handle async function calls

Open sakopqiu opened this issue 4 years ago • 0 comments

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);


sakopqiu avatar Nov 04 '21 09:11 sakopqiu