Skip to content

Commit 7fd0b88

Browse files
committed
Add log info in case of enqueuing timeout
1 parent 1c962c2 commit 7fd0b88

File tree

1 file changed

+35
-0
lines changed

1 file changed

+35
-0
lines changed

src/main/java/com/rabbitmq/client/impl/NettyFrameHandlerFactory.java

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@
5151
import java.net.InetSocketAddress;
5252
import java.net.SocketAddress;
5353
import java.time.Duration;
54+
import java.util.Queue;
55+
import java.util.concurrent.ConcurrentLinkedQueue;
5456
import java.util.concurrent.CountDownLatch;
5557
import java.util.concurrent.ExecutionException;
5658
import java.util.concurrent.TimeUnit;
@@ -438,9 +440,42 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception
438440
}
439441
}
440442

443+
private static class Event {
444+
private final long time;
445+
private final String label;
446+
447+
public Event(long time, String label) {
448+
this.time = time;
449+
this.label = label;
450+
}
451+
452+
@Override
453+
public String toString() {
454+
return this.label + " " + this.time;
455+
}
456+
}
457+
458+
private static final int MAX_EVENTS = 100;
459+
private final Queue<Event> events = new ConcurrentLinkedQueue<>();
460+
461+
private void logEvents() {
462+
if (this.events.size() > 0) {
463+
long start = this.events.peek().time;
464+
LOGGER.info("channel writability history:");
465+
events.forEach(e -> LOGGER.info("{}: {}", (e.time - start) / 1_000_000, e.label));
466+
}
467+
}
468+
441469
@Override
442470
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
443471
boolean canWrite = ctx.channel().isWritable();
472+
Event event = new Event(System.nanoTime(), Boolean.toString(canWrite));
473+
if (this.events.size() >= MAX_EVENTS) {
474+
this.events.poll();
475+
this.events.offer(event);
476+
}
477+
this.events.add(event);
478+
444479
if (this.writable.compareAndSet(!canWrite, canWrite)) {
445480
if (canWrite) {
446481
CountDownLatch latch = writableLatch.getAndSet(new CountDownLatch(1));

0 commit comments

Comments
 (0)