Recipe: how to auto-close idle connections
Requirement:
I want to close idle connections for some applications, and make sure that connections stay open 24/7 for other applications.
Solution:
Edit the <AutoCloseIdleClients> element in my Server.xml file – then add and configure <AutoCloseIdleClients> elements in my Vhost.xml or Application.xml files. Season to taste.
Background and Analysis:
Bear with me. I’m picking my way through this.
I ran up against a situation in my home-grown connection pooling application. I noticed that connected clients – including pool-to-pool connections – were disconnecting. I also noticed that I was exceeding the 10-connection limit on the developer version of FMIS, by the way. So, I decided to get to the bottom of the issue and find out whether the disconnects were caused by the server maxing out the connection allotment, or if they were caused by some sort of timeout.
Adobe book-and-verse is a little confusing on the matter of the timeout. The config-admin guide tells me that the timeout is disabled by default. But it also tells me that the default timeout is 10 minutes. So, which is it?
A closer inspecton reveals that if one switches the default <AutoCloseIdleClients> by merely changing the enable attribute from “false” to “true”, then you will indeed enable a global 10 minute timeout – because the Server.xml as it ships sets the MaxTimeOut to 600 seconds:
<AutoCloseIdleClients enable="false"> <CheckInterval>60</CheckInterval> <MaxIdleTime>600</MaxIdleTime> </AutoCloseIdleClients>
All this seems pretty straightforward, I guess. But then again, the way the documentation is written, it makes it seem like there’s a 10-minute timeout lurking around even if <AutoCloseIdleClients> is not enabled.
I’m conducting an informal inquiry at the moment – I’ve got a bunch of clients connected to my pool They’ve been idle for about 30 minutes now. None have disconnected of their own accord – so I guess I can conclude that there is no 10-minute default lurking somewhere in the background. Enabled=”false” means enabled=”false”.
But it does raise the question for me: if I did want to enable an auto timeout for a client, but not for the pool, how would I go about doing that?
What I might try goes as follows:
Server.xml – flip AutoCloseIdleClients enabled to true. Maybe even give it a massive, healthy timeout value, say, 60 minutes. (Question for Adobe: other that enabled=false, is there a value for “infinity – and beyond”? How about -1?….)
Pool application: set AutoCloseIdleClients enabled to false in the Application.xml file. That way, the pool never hangs up its connections due to timeout.
Client application: set AutoCloseIdleClients to true, and feed it my timeout value in the Application.xml file.
In theory, this should work. Guess we’ll see…