title: Yaws - socket_closed_remotely
body: <p>Hello fellow Erlangers :)</p>
  
  <p>Just another Erlang enthusiast playing with the language here. I have a very simple YAWS app module which works fine when accessed by single clients. However, when I try to spawn multiple concurrent clients, some of those clients start receiving errors (even if the number of those clients is very low, say 10). Any idea what can be causing it?</p>
  
  <p>Illustrating code:</p>
  
  <p><strong>App Module</strong></p>
  
  <pre><code>out(Arg) -&gt;
    io:format("got something!\n"),
    Method = extract_method(Arg),
    handle(Method, Arg).
  </code></pre>
  
  <p><strong>Client</strong></p>
  
  <pre><code>client(SenderPID) -&gt;
  case httpc:request(
    put,
    {
      "http://localhost:8080/storageunit",
      [],
      "application/x-www-form-urlencoded",
      ""
    }, [], []) of
      { error, Reason } -&gt; io:format("Server responded with an error: ~p.\n", [Reason]);
      { ok, _ } -&gt; ok
    end,
    SenderPID ! 'FINISHED'.
  
  client_spawner(_SenderPID, 0) -&gt; io:format("Done.\n");
  client_spawner(SenderPID, Times) -&gt;
    spawn(concurrent, client, [SenderPID]),
    client_spawner(SenderPID, Times - 1).
  </code></pre>
  
  <p>The errors I'm getting:</p>
  
  <blockquote>
    <p>Server responded with an error: socket_closed_remotely.</p>
  </blockquote>
  
  <p>The last piece of info is:</p>
  
  <ul>
  <li>10 concurrent clients - from 2 to 5 errors on average</li>
  <li>100-100000 concurrent clients - 50% errors on average</li>
  </ul>
  
  <p>I thought my handling code causes it, but in scenarios where the clients receive httpc errors, the server doesn't even react with a "got something!".</p>
  
  <p>I'm sure I'm missing something trivial, can you help?</p>
  
  <p>Regards,
  Piotr</p>