Catch AlreadyClosedException and retry connection AlreadyClosedException thrown by AMQConnection#createChannel() was never caught which killed the rabbitmq publisher when connection was closed unexpectedly. Bug: Issue 9652 Change-Id: Iba218acae5f7987d1728b7d5510cab53621fe980
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java index 6284b86..3ae3104 100644 --- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java +++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/session/type/AMQPSession.java
@@ -21,6 +21,7 @@ import com.googlesource.gerrit.plugins.rabbitmq.config.section.Message; import com.googlesource.gerrit.plugins.rabbitmq.config.section.Monitor; import com.googlesource.gerrit.plugins.rabbitmq.session.Session; +import com.rabbitmq.client.AlreadyClosedException; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabbitmq.client.ConnectionFactory; @@ -120,7 +121,7 @@ ch.addShutdownListener(channelListener); failureCount.set(0); LOGGER.info(MSG("Channel #{} opened."), ch.getChannelNumber()); - } catch (IOException ex) { + } catch (IOException | AlreadyClosedException ex) { LOGGER.error(MSG("Failed to open channel."), ex); failureCount.incrementAndGet(); }