Make sure unbinding of forwarded tunnel endpoint occurs even if tear-down event signalling threw an exception
@@ -267,13 +267,16 @@ public class DefaultForwardingFilter
}
SshdSocketAddress boundAddress = new SshdSocketAddress(bound);
+ try {
signalTearingDownExplicitTunnel(boundAddress, true, remote);
+ } finally {
try {
acceptor.unbind(bound);
} catch (RuntimeException e) {
signalTornDownExplicitTunnel(boundAddress, true, remote, e);
throw e;
}
+ }
signalTornDownExplicitTunnel(boundAddress, true, remote, null);
} else {
@@ -582,8 +585,10 @@ public class DefaultForwardingFilter
SshdSocketAddress local, SocksProxy proxy, InetSocketAddress bound) throws IOException {
boolean debugEnabled = log.isDebugEnabled();
if ((bound != null) || (proxy != null)) {
- signalTearingDownDynamicTunnel(local);
+ try {
+ signalTearingDownDynamicTunnel(local);
+ } finally {
try {
try {
if (proxy != null) {
@@ -610,6 +615,7 @@ public class DefaultForwardingFilter
signalTornDownDynamicTunnel(local, e);
throw e;
}
+ }
signalTornDownDynamicTunnel(local, null);
} else {
