This bug was discovered while investigating
This bug also caused
There exist a race condition where an application could create a new session (recreating due to an exception or a completely new session in the midst of failover) before the connection is open.
This results in session attach being sent before the connection negotiation is completed. All though the connect method and the createSession method in Connection.java contends for the same lock, the connect method which acquires it early, will releases the lock when it waits (until the connection achieves OPEN state) and the createSession method waiting on the lock will get it and continue.
Usually this only becomes an issue during failover, as during the initial connection creation, the application thread that creates the connection will wait until the connect method returns before it creates a session.
However If an application tries to create a connection in one thread and several other threads try to create sessions from that connection, and if those threads don't coordinate properly to check if the connection is opened, then this same race condition is present.