[QFJ-638] SocketSynchronousWrites=Y Hangs Threads on Session responderSync Created: 03/Oct/11  Updated: 02/Apr/15  Resolved: 13/Feb/14

Status: Closed
Project: QuickFIX/J
Component/s: Engine
Affects Version/s: 1.5.1
Fix Version/s: 1.6.0

Type: Bug Priority: Default
Reporter: James Olsen Assignee: Christoph John
Resolution: Fixed Votes: 0
Labels: None

Attachments: Text File QFJ-638.patch    
Issue Links:
Relates
relates to QFJ-738 Deadlock on disconnect Closed

 Description   

As first noted by Parwinder Sekhon in QFJ-433 and further elaborated (perhaps confusingly) in QFJ-484, the locking used in the following Session method causes threads to hang when SocketSynchronousWrites is enabled.

private boolean send(String messageString) {
getLog().onOutgoing(messageString);
synchronized (responderSync) {
if (!hasResponder())

{ getLog().onEvent("No responder, not sending message: " + messageString); return false; }

return getResponder().send(messageString);
}
}

Slow consumers do exist in the real world. We therefore sometimes have to use SocketSynchronousWrites=Y in order to avoid memory leaks due to all the WriteFuture objects that are generated. The problem with the current locking is that the background thread that handles heartbeats and forces logouts etc can get stuck waiting for one of these slow consumers. This means that the Session will not be logged out even if it has missed many heartbeats. Even worse, the same background thread is used for other Sessions on the same Connector so they are also impacted even if they are not synchronous.

Changing the code as follows resolves these issues.

private boolean send(String messageString) {
getLog().onOutgoing(messageString);
Responder responder;
synchronized (responderSync)

{ responder = this.responder; }

if (responder == null)

{ getLog().onEvent("No responder, not sending message: " + messageString); return false; }

return responder.send(messageString);
}

The message sequence number locking used in the sendRaw method seems sufficient to coordinate any multi-threaded message senders given that the above change otherwise opens a hole.

The use of a ReentrantLock as discussed in QFJ-484 is not required for this issue. As shown above, the existing responderSync String object is sufficient.



 Comments   
Comment by James Olsen [ 03/Oct/11 ]

Patch attached.

Generated at Mon May 06 00:20:20 UTC 2024 using JIRA 7.5.2#75007-sha1:9f5725bb824792b3230a5d8716f0c13e296a3cae.