简体   繁体   中英

Undertow on Spring leaks connections

I'm using Spring Boot (1.3.O.M5) with Undertow. Recently, I've found that when I use the

lsof -p $(pidof java)

command after a few hours, it presents me with about 700 lines, most of which are established TCP connections to clients, even though almost nobody entered the page in the recent hour (and when I connect to the site, my connection is gone after about 5 minutes).

Most likely this is the source of my java.net.SocketException: Too many open files - which I got every couple of days (requiring me to restart the app) before I noticed the stale connections. I increased the max open files limit in the system, but it obviously seems a short-term solution.

I would appreciate help with the issue. Thanks!

Try to set httpServerExchange.setPersistent(false); , it helps me when I were having same problems. And yes - it causes too many open files error because it exceed limit with file descriptors

Undertow does not have a default connection timeout, you need to set it using something like:

Undertow.builder().setServerOption(UndertowOptions.NO_REQUEST_TIMEOUT, 60000)

This will tell Undertow to close the connection after a 60s with no requests from a client.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM