Want to start off by saying thank you for providing this library... while troubleshooting a main thread blocking issue in a Koa app and we systematically removed each element of the app from our server.js file only to find that the main thread will report blocked with the simplest of Node apps.
const Koa = require('koa');
const app = new Koa();
const blocked = require('blocked');
blocked(function(ms) {
console.log(`!!! >>> MAIN THREAD Blocked for ${ms}ms.`);
}, {threshold:10});
app.use(ctx => {
ctx.body = '{"debug":"return from debug"}';
});
app.listen(4000);
const http = require('http')
const port = 4000
const blocked = require('blocked');
blocked(function(ms) {
console.log(`!!! >>> MAIN THREAD Blocked for ${ms}ms.`);
}, {threshold:10});
const requestHandler = (request, response) => {
response.end('{"debug":"return from debug"}')
}
const server = http.createServer(requestHandler)
server.listen(port, (err) => {
if (err) {
return console.log('error:', err)
}
console.log(`http server listening on port: ${port}`)
})
http server listening on port: 4000
!!! >>> MAIN THREAD Blocked for 35ms.
!!! >>> MAIN THREAD Blocked for 30ms.
!!! >>> MAIN THREAD Blocked for 45ms.
!!! >>> MAIN THREAD Blocked for 18ms.
!!! >>> MAIN THREAD Blocked for 11ms.
!!! >>> MAIN THREAD Blocked for 11ms.
!!! >>> MAIN THREAD Blocked for 36ms.
...
With either of the code sample above, the main thread will report blocked when the application is idle with no requests inbound to the web server and this points to a node.js internal blocking or node-blocked is misreporting blocking in certain instances. I am new to this level of internals and apologize if this is a known item.