Note that there are some explanatory texts on larger screens.

plurals
  1. POapr_socket_recv: An established connection was aborted by the software in your host machine
    text
    copied!<p>I'm creating a small server using <code>java.nio</code>, but when trying to stress test it I keep getting messages about the connection being reset on the server side, or more specifically:</p> <pre><code>apr_socket_recv: An established connection was aborted by the software in your host machine </code></pre> <p>I've tried to narrow it down to the most simple of loops, but still no luck. I can get the error after a hundred or so connections, or maybe just after 1 or 2.</p> <p>Here's the server loop:</p> <pre><code>byte[] response = ("HTTP/1.1 200 OK\r\n" + "Server: TestServer\r\n" + "Content-Type: text/html\r\n" + "\r\n" + "&lt;html&gt;&lt;b&gt;Hello&lt;/b&gt;&lt;/html&gt;").getBytes(); SocketChannel newChannel = null; while (active) { try { //get a new connection and delegate it. System.out.print("Waiting for connection.."); newChannel = serverSocketChannel.accept(); System.out.println("ok"); newChannel.configureBlocking(true); newChannel.write(ByteBuffer.wrap(response)); } catch (IOException e) { e.printStackTrace(); } finally { try { newChannel.close(); } catch (IOException ex) { Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex); } } } </code></pre> <p>I've tried checking if the write didn't write all requested byte, but it seemingly does. Interestingly enough, calling <code>System.gc()</code> after each <code>newChannel.close()</code> makes the problem disappear (but in return, it's horribly slow). So either I'm not releasing all resources I should release, or the application just needs a pause..</p> <p>I'm losing all of my best years on this. Oh, and by the way.. if I ignore writing to the channel and just close after I accept the connection, the problem <i>still</i> doesn't go away.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload