Netty bug fix: Do not use weakValues in a cache where we track outstanding responses.
diff --git a/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java b/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java
index e10ba29..33870e2 100644
--- a/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java
+++ b/utils/netty/src/main/java/org/onlab/netty/NettyMessagingService.java
@@ -67,7 +67,6 @@
private final AtomicLong messageIdGenerator = new AtomicLong(0);
private final Cache<Long, SettableFuture<byte[]>> responseFutures = CacheBuilder.newBuilder()
.maximumSize(100000)
- .weakValues()
// TODO: Once the entry expires, notify blocking threads (if any).
.expireAfterWrite(10, TimeUnit.MINUTES)
.build();
@@ -174,7 +173,12 @@
.withType(type)
.withPayload(payload)
.build();
- sendAsync(ep, message);
+ try {
+ sendAsync(ep, message);
+ } catch (IOException e) {
+ responseFutures.invalidate(messageId);
+ throw e;
+ }
return futureResponse;
}
@@ -293,7 +297,8 @@
if (futureResponse != null) {
futureResponse.set(message.payload());
} else {
- log.warn("Received a reply. But was unable to locate the request handle");
+ log.warn("Received a reply for message id:[{}]. "
+ + "But was unable to locate the request handle", message.id());
}
} finally {
NettyMessagingService.this.responseFutures.invalidate(message.id());