I have node10 express app, something like:
const app = express();
app.use(function(req, res, next) { ..}
app.use( bodyParser.text({
limit: '1mb',
type: '*/*',
})
);
more of those..
app.post('myApiName', [(req, res, next) => {..}, (req, res, next) => {..} .. etc many more]);
https.createServer(sslOptions, app) ...
But with many more routes and middlewares.
Due to blocked issues I have, in which the cpu is working on something and is "not responding" for seconds, I added https://github.com/naugtur/blocked-at/blob/master/README.md module. But most of the stack trace it provides me is starting with at Server.connectionListener (_http_server.js:319:3),...
. and in the readme, it says about this:
In some cases your code is not directly called and tracking it down will still be difficult. See how the HTTP test case produces a stack pointing to Server.connectionListener as the slow function, because everything inside of it is synchronously called. You can always wrap your handlers' code in setImmediate if you become desperate. Or use resources.
.
I understand I need to run my handlers from another "origin" that will start from another task in the event loop (I'm probably not phrasing well), but I don't really understand what exactly I can do using the suggestion of setImmediate. I saw there is some npm library https://www.npmjs.com/package/express-async-handler for error handling, but I'm still not sure exactly how my code should look (especially because I have many handlers and middlewares).
I'll be happy to get some suggestions or some code snippets to understand how to get a better stack trace.