Skip to content

Commit 0d25127

Browse files
committed
Handle exception in NIO loop to avoid abrupt termination
Fixes #611 (cherry picked from commit bd38524)
1 parent 2878464 commit 0d25127

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
@@ -118,7 +118,14 @@ public void run() {
118118
registration = registrationIterator.next();
119119
registrationIterator.remove();
120120
int operations = registration.operations;
121-
registration.state.getChannel().register(selector, operations, registration.state);
121+
try {
122+
if (registration.state.getChannel().isOpen()) {
123+
registration.state.getChannel().register(selector, operations, registration.state);
124+
}
125+
} catch (Exception e) {
126+
// can happen if the channel has been closed since the operation has been enqueued
127+
LOGGER.info("Error while registering socket channel for read: {}", e.getMessage());
128+
}
122129
}
123130

124131
if (select > 0) {

0 commit comments

Comments
 (0)