4

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!

Jakub Kozłowski
  • 493
  • 1
  • 6
  • 13
  • Also, an UndertowEmbeddedServletContainerFactory bean with setSessionTimeout(3) didn't shorten the session timeout to 3 seconds. Neither did server.session.timeout=3 :( – Jakub Kozłowski Sep 09 '15 at 01:20
  • What kind of connections? External? To internal systems? Figure out the connections to get a feel of what part of the application it is happening. Also the session timeout is for HTTP sessions and doesn't do anything for connections. – M. Deinum Sep 09 '15 at 06:06
  • That's what I thought since I saw the property. It never hurts to try, though. The connections are just TCP connections to the devices visiting the website. – Jakub Kozłowski Sep 09 '15 at 15:23
  • Could be the devices keeping connections open might be dependent on the device/os? Its been a while but there are probably ways of setting the connection timeout on the server or to close inactive connections. – M. Deinum Sep 09 '15 at 18:32
  • I don't know. The connections seem to be made from mobile networks (I can see the carriers' names in the addresses - at least in a vast majority), and that's all I know about them. – Jakub Kozłowski Sep 09 '15 at 21:37

2 Answers2

3

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.

Stuart Douglas
  • 847
  • 5
  • 4
  • I just changed this in upstream Undertow to default to 10 minutes, see https://issues.jboss.org/browse/UNDERTOW-630 – Stuart Douglas Feb 10 '16 at 01:18
  • I set it in Application.main, just after I start the SpringApplication... and writing this, I realize I probably should've done that before starting the app - but it doesn't work ATM. I had 200 open files when starting the app in prod and have 600 now with about 7 devices accessing the website. – Jakub Kozłowski Feb 10 '16 at 18:50
2

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