Skip to content

Commit bd38524

Browse files
committed
Handle exception in NIO loop to avoid abrupt termination
Fixes rabbitmq#611
1 parent 838cc55 commit bd38524

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/main/java/com/rabbitmq/client/impl/nio/NioLoop.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,14 @@ public void run() {
115115
registration = registrationIterator.next();
116116
registrationIterator.remove();
117117
int operations = registration.operations;
118-
registration.state.getChannel().register(selector, operations, registration.state);
118+
try {
119+
if (registration.state.getChannel().isOpen()) {
120+
registration.state.getChannel().register(selector, operations, registration.state);
121+
}
122+
} catch (Exception e) {
123+
// can happen if the channel has been closed since the operation has been enqueued
124+
LOGGER.info("Error while registering socket channel for read: {}", e.getMessage());
125+
}
119126
}
120127

121128
if (select > 0) {

0 commit comments

Comments
 (0)