Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot - Lot of invalid requests and Socket accept failed java.io.IOException: Too many open files

I have running machine with Spring (Spring Boot 1.5.2.RELEASE) application. Recently I'm receiving a lot of warnings in my log file:

.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

I've checked with tcpdump and a lot of request don't have body (empty/null) or have incorrect body e.g. \00\00\00\00\00\00\00speed":"23.3","user_id":106312}

The biggest problem is that after some time I'm starting to receiving exceptions in my app:

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)

ulimit -n says that limit of open files is set to 65536 so I think it's big enough.

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?

like image 1000
user3626048 Avatar asked Oct 29 '18 08:10

user3626048


1 Answers

I guess you use web socket with spring boot. You can listen on only 65535 port maximum, you can't exceed this amount of value on a machine. You should check if you close properly your sockets.

like image 184
Djory Krache Avatar answered Nov 12 '22 12:11

Djory Krache