Details
-
Type:
Bug
-
Status:
Open
-
Priority:
Major
-
Resolution: Unresolved
-
Affects Version/s: None
-
Fix Version/s: None
-
Labels:None
-
Number of attachments :
Description
I found a race condition in the MultiplexingRequestor causing the failure in my previous post. This happens when using synchronic callback.
Consider the following code
callBack.onProgress(1);
callBack.onProgress(2);
callBack.onProgress(3);
MultiplexingRequestor:
ReplyHandler replyHandler = (ReplyHandler) handler;
boolean complete = replyHandler.handle(message);
//************************************************************************************
// Race Condition: The calling thread is unlocked by replyHandler.handle(message) and
// is able to call a next request where a new futureHandler is put in the requestMap.
//
// This new entry is deleted in the next line causing the warning
// "Response received for unknown correlationID:" on the response of this request
//************************************************************************************
if (complete) {
requestMap.remove(correlationID);
}
Solution is to synchronize the previous block with the put in the request function
public void onMessage(Message message) {
...
ReplyHandler replyHandler = (ReplyHandler) handler;
synchronized (requestMap) {
boolean complete = replyHandler.handle(message);
if (complete)
}
...
}
And
public Message request(Destination destination, Message message, long timeout) throws JMSException {
...
if (future == null) {
FutureHandler futureHandler = new FutureHandler();
future = futureHandler;
if (requestMap.get(correlationID) != null)
log.warn("Overwriting handler: " + requestMap.get(correlationID));
synchronized (requestMap)
{ requestMap.put(correlationID, futureHandler, timeout); } }
...
}
Regards,
Tom L.