Fix possible GenericMsgTemplate race condition

Fix a potential race condition with GenericMessagingTemplate's inner
TemporaryReplyChannel class.

Prior to this commit the `hasReceived` member variable was read after
calling `replyLatch.countDown()`.

Issue: SPR-11206
master
Phillip Webb 11 years ago
parent f57c4a09ee
commit a1529d498e
  1. 4
      spring-messaging/src/main/java/org/springframework/messaging/core/GenericMessagingTemplate.java

@ -119,7 +119,6 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
} }
} }
@SuppressWarnings("unchecked")
@Override @Override
protected final Message<?> doReceive(MessageChannel channel) { protected final Message<?> doReceive(MessageChannel channel) {
@ -230,13 +229,14 @@ public class GenericMessagingTemplate extends AbstractDestinationResolvingMessag
public boolean send(Message<?> message, long timeout) { public boolean send(Message<?> message, long timeout) {
this.replyMessage = message; this.replyMessage = message;
boolean alreadyReceivedReply = this.hasReceived;
this.replyLatch.countDown(); this.replyLatch.countDown();
String errorDescription = null; String errorDescription = null;
if (this.hasTimedOut) { if (this.hasTimedOut) {
errorDescription = "Reply message received but the receiving thread has exited due to a timeout"; errorDescription = "Reply message received but the receiving thread has exited due to a timeout";
} }
else if (this.hasReceived) { else if (alreadyReceivedReply) {
errorDescription = "Reply message received but the receiving thread has already received a reply"; errorDescription = "Reply message received but the receiving thread has already received a reply";
} }
else if (this.hasSendFailed) { else if (this.hasSendFailed) {

Loading…
Cancel
Save