Saturday, September 29, 2007

Stale MySql Connections In SJSAS

If you use the Sun Java System Application Server (SJSAS) with the MySQL database application, you will eventually notice that communication between the two products "goes to sleep" after prolonged periods of inactivity. I've traced this to the following root cause:
: Communications link failure due to underlying exception:

java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.write0(Native Method)
at sun.nio.ch.SocketDispatcher.write(SocketDispatcher.java:33)
at sun.nio.ch.IOUtil.writeFromNativeBuffer(IOUtil.java:104)
at sun.nio.ch.IOUtil.write(IOUtil.java:75)
at sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:334)
at com.sun.enterprise.server.ss.provider.ASOutputStream.write(ASOutputStream.java:138)
at java.io.BufferedOutputStream.flushBuffer(BufferedOutputStream.java:65)
at java.io.BufferedOutputStream.flush(BufferedOutputStream.java:123)
at com.mysql.jdbc.MysqlIO.send(MysqlIO.java:2637)

Something goes stale during down time and it can't be revived until you restart the server itself. Restarting the database doesn't help. For servers always being accessed, the issue won't be seen. I'd most likely blame the application server if it were up to me, but I'm not conclusive on that, since it may also mean that a socket connection to MySQL's port failed. Just not sure!
An easy workaround is to implement a thread in the application that keeps exercising the connection if it hasn't been used in a specified period of time. When I did this, my problem disappeared.

Friday, September 28, 2007

Weird Windows