Skip to content

Commit 54c1342

Browse files
author
Steve Powell
committed
Rework handleChannelKiller to close channel only (if possible).
1 parent 4547642 commit 54c1342

File tree

1 file changed

+19
-14
lines changed

1 file changed

+19
-14
lines changed

src/com/rabbitmq/client/impl/DefaultExceptionHandler.java

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import java.io.IOException;
2020

2121
import com.rabbitmq.client.AMQP;
22+
import com.rabbitmq.client.AlreadyClosedException;
2223
import com.rabbitmq.client.Channel;
2324
import com.rabbitmq.client.Connection;
2425
import com.rabbitmq.client.Consumer;
@@ -55,23 +56,27 @@ public void handleConsumerException(Channel channel, Throwable exception,
5556
+ " for channel " + channel);
5657
}
5758

58-
protected void handleChannelKiller(Channel channel,
59-
Throwable exception,
60-
String what)
61-
{
62-
// TODO: Convert to logging framework
63-
System.err.println(what + " threw an exception for channel " +
64-
channel + ":");
59+
protected void handleChannelKiller(Channel channel, Throwable exception, String what) {
60+
// TODO: log the exception
61+
System.err.println(what + " threw an exception for channel " + channel + ":");
6562
exception.printStackTrace();
6663
try {
67-
((AMQConnection) channel.getConnection()).close(AMQP.INTERNAL_ERROR,
68-
"Internal error in " + what,
69-
false,
70-
exception);
64+
channel.close();
65+
} catch (AlreadyClosedException ace) {
66+
//noop
7167
} catch (IOException ioe) {
72-
// Man, this clearly isn't our day.
73-
// Ignore the exception? TODO: Log the nested failure
68+
// TODO: log the failure
69+
System.err.println("Failure during close of channel " + channel + " after " + exception + ":");
70+
ioe.printStackTrace();
71+
AMQConnection conn = (AMQConnection) channel.getConnection();
72+
try {
73+
conn.close(AMQP.INTERNAL_ERROR, "Internal error closing channel for " + what,
74+
false, ioe);
75+
} catch (IOException ioeH) {
76+
// TODO: log the failure
77+
System.err.println("Failure during close of connection " + conn + " after " + ioe + ":");
78+
ioeH.printStackTrace();
79+
}
7480
}
75-
7681
}
7782
}

0 commit comments

Comments
 (0)