title: React app with Server-side rendering crashes with load
body: <p>I'm using <code>react-boilerplate</code> (with react-router, sagas, express.js) for my React app and on top of it I've added SSR logic so that once it receives an HTTP request it renders react components to string based on URL and sends HTML string back to the client.</p>
  
  <p>While react rendering is happening on the server side, it also makes <code>fetch</code> request through sagas to some APIs (up to 5 endpoints based on the URL) to get data for components before it actually renders the component to string.</p>
  
  <p>Everything is working great if I make only several request to the Node server at the same time, but once I simulate load of 100+ concurrent requests and it starts processing it then at some point it crashes with no indication of any exception. </p>
  
  <p>What I've noticed while I was trying to debug the app is that once 100+ incoming requests begin to be processed by the Node server it sends requests to APIs at the same time but receives no actual response until it stops stacking those requests.</p>
  
  <p><strong>The code that's used for rendering on the server side:</strong></p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="true">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>async function renderHtmlDocument({ store, renderProps, sagasDone, assets, webpackDllNames }) {
    // 1st render phase - triggers the sagas
    renderAppToString(store, renderProps);
  
    // send signal to sagas that we're done
    store.dispatch(END);
  
    // wait for all tasks to finish
    await sagasDone();
  
    // capture the state after the first render
    const state = store.getState().toJS();
  
    // prepare style sheet to collect generated css
    const styleSheet = new ServerStyleSheet();
  
    // 2nd render phase - the sagas triggered in the first phase are resolved by now
    const appMarkup = renderAppToString(store, renderProps, styleSheet);
  
    // capture the generated css
    const css = styleSheet.getStyleElement();
  
    const doc = renderToStaticMarkup(
      &lt;HtmlDocument
        appMarkup={appMarkup}
        lang={state.language.locale}
        state={state}
        head={Helmet.rewind()}
        assets={assets}
        css={css}
        webpackDllNames={webpackDllNames}
      /&gt;
    );
    return `&lt;!DOCTYPE html&gt;\n${doc}`;
  }
  
  // The code that's executed by express.js for each request
  function renderAppToStringAtLocation(url, { webpackDllNames = [], assets, lang }, callback) {
    const memHistory = createMemoryHistory(url);
    const store = createStore({}, memHistory);
  
    syncHistoryWithStore(memHistory, store);
  
    const routes = createRoutes(store);
  
    const sagasDone = monitorSagas(store);
  
    store.dispatch(changeLocale(lang));
    
    match({ routes, location: url }, (error, redirectLocation, renderProps) =&gt; {
      if (error) {
        callback({ error });
      } else if (renderProps) {
        renderHtmlDocument({ store, renderProps, sagasDone, assets, webpackDllNames })
          .then((html) =&gt; {
            callback({ html });
          })
          .catch((e) =&gt; callback({ error: e }));
      } else {
        callback({ error: new Error('Unknown error') });
      }
    });
  }</code></pre>
  </div>
  </div>
  </p>
  
  <hr>
  
  <p>So my assumption is that something is going wrong once it receives too many HTTP requests which in turn generates even more requests to API endpoints to render react components. </p>
  
  <p>I've noticed that it blocks event loop for 300ms after <code>renderAppToString()</code> for every client request, so once there are 100 concurrent requests it blocks it for about 10 seconds. I'm not sure if that's a normal or bad thing though.</p>
  
  <p>Is it worth trying to limit simultaneous requests to Node server? </p>
  
  <p>I couldn't find much information on the topic of SSR + Node crashes. So I'd appreciate any suggestions as to where to look at to identify the problem or for possible solutions if anyone has experienced similar issue in the past.</p>