The issue is setting a login timeout is also causing the queries to time out within that time. I did some debugging of the code and following is what I saw.
It appears that if the user has asked for login timeout, then during the connection setup time , we call setSoTimeout on the the socket which is used for communication.
The api defination for setSoTimeout api on Socket says follows
public void setSoTimeout(int timeout) throws SocketException
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a
non-zero timeout, a read() call on the InputStream associated with this Socket will block for only this
amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the
Socket is still valid. The option must be enabled prior to entering the blocking operation to have effect.
The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.
timeout - the specified timeout, in milliseconds.
SocketException - if there is an error in the underlying protocol, such as a TCP error.
So, it looks like that this setSoTimeout setting is applicable not just for the login time but also for every interaction after that
which in our test case includes the query execution.
The code path for setSoTimeout call on socket through our connection set up is as follows
Thread [main] (Suspended)
NetAgent.<init>(NetConnection, LogWriter, int, String, int, int) line: 142
NetConnection.newAgent_(LogWriter, int, String, int, int) line: 1016
NetConnection(Connection).<init>(LogWriter, int, String, int, String, Properties) line: 322
NetConnection.<init>(NetLogWriter, int, String, int, String, Properties) line: 208
ClientJDBCObjectFactoryImpl.newNetConnection(LogWriter, int, String, int, String, Properties) line: 270
ClientDriver.connect(String, Properties) line: 140
DriverManager.getConnection(String, Properties, ClassLoader) line: 572
DriverManager.getConnection(String) line: 218
Derby2026LoginTimeout.main(String) line: 52
In the stack above, Derby2026LoginTimeout is the repro provided in the jira. I just changed the repro's name and the jdbc url inside the repro.
I am not sure at this point how(or if it can be done) but may be a fix would be to have the setSoTimeout be set only while the connection is being made. Once we have the connection, go back and rest the setSoTimeout to 0. I noticed following api in derby.client.net.NetAgent.java
protected void setTimeout(int timeout)
This api changes the timeout on socket to the passed value. I wonder if this api can be somehow used to change the timeout value to 0 after the connection has been established. As of right now, there is only one caller to NetAgent.setTimeout method and that call is from derby.client.Net.NetConnection40.isValid(int) method.