title: What happens to nodejs server requests when the process is blocked
body: <p>What happens to incoming requests when a nodejs server is blocked? There are times when the server will be blocked because it is chewing through something computationally expensive, or perhaps doing some synchronous IO (e.g. writing to a sqlite database). This is best described with an example:</p>
  <p>given a server like this:</p>
  <pre class="lang-js prettyprint-override"><code>const { execSync } = require('child_process')
  const express = require('express')
  const app = express()
  const port = 3000
  
  // a synchronous (blocking) sleep function
  function sleep(ms) {
    execSync(`sleep ${ms / 1000}`)
  }
  
  app.get('/block', (req, res) =&gt; {
    sleep(req.query.ms)
    res.send(`Process blocked for ${req.query.ms}ms.`)
  })
  app.get('/time', (req, res) =&gt; res.send(new Date()))
  
  app.listen(port, () =&gt; console.log(`Example app listening at http://localhost:${port}`))
  </code></pre>
  <p>I can block the nodejs process like so:</p>
  <pre class="lang-sh prettyprint-override"><code># block the server for two seconds
  curl http://localhost:3000/block\?ms\=2000
  </code></pre>
  <p>and while it is blocked attempt to make another request to the server:</p>
  <pre class="lang-sh prettyprint-override"><code>curl http://localhost:3000/time
  </code></pre>
  <p>the second request will hang until the blocking call is completed, and then respond with the expected datetime. My question is, what specifically is happening to the request while the nodejs process is blocked?</p>
  <ul>
  <li>Does node read in the request using some low level c++ and put it into a queue? Is backpressure involved here?</li>
  <li>Is the unix kernel involved here? Does it know to put a request on some kind of queue while a server refuses to respond?</li>
  <li>Is it just as simple as curl waiting on a response from a socket indefinitely?</li>
  <li>What happens if the server is blocked and 10,000 new requests hit the server? Will they all be serviced as soon as the server becomes unblocked? (assuming there is no load balancer or other timeout mechanisms in between the client &amp; server)</li>
  </ul>
  <p>Finally, I understand that blocking nodejs is bad practice but I am not asking about best practices. I want to understand what nodejs does under stressful circumstances like those described here.</p>