title: Spring Boot - Lot of invalid requests and Socket accept failed java.io.IOException: Too many open files
body: <p>I have running machine with <code>Spring (Spring Boot 1.5.2.RELEASE)</code> application. Recently I'm receiving a lot of warnings in my log file:</p>
  
  <pre><code>.w.s.m.s.DefaultHandlerExceptionResolver : Failed to read HTTP message: org.springframework.http.converter.HttpMessageNotReadableException: Could not read document: null; nested exception is java.net.SocketTimeoutException
  </code></pre>
  
  <p>I've checked with <code>tcpdump</code> and a lot of request don't have body (empty/null) or have incorrect body e.g. <code>\00\00\00\00\00\00\00speed":"23.3","user_id":106312}</code></p>
  
  <p>The biggest problem is that after some time I'm starting to receiving exceptions in my app:</p>
  
  <pre><code>org.apache.tomcat.util.net.NioEndpoint   : Socket accept failed
  
  java.io.IOException: Too many open files
      at sun.nio.ch.ServerSocketChannelImpl.accept0(Native Method)
      at sun.nio.ch.ServerSocketChannelImpl.accept(ServerSocketChannelImpl.java:241)
      at org.apache.tomcat.util.net.NioEndpoint$Acceptor.run(NioEndpoint.java:443)
      at java.lang.Thread.run(Thread.java:745)
  </code></pre>
  
  <p><code>ulimit -n</code> says that limit of open files is set to <code>65536</code> so I think it's big enough.</p>
  
  <p>I'm assuming that receiving big amount of invalid requests causes IOException but why? And what should I do to avoid it and fix it?</p>