[#1654] Remove AbstractChannel.doPreClose() and notify close future on register failure. Based on patch of @jpinner
This commit is contained in:
parent
6278d88d2f
commit
cffbba94ee
@ -415,6 +415,7 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
"Force-closing a channel whose registration task was unaccepted by an event loop: {}",
|
"Force-closing a channel whose registration task was unaccepted by an event loop: {}",
|
||||||
AbstractChannel.this, t);
|
AbstractChannel.this, t);
|
||||||
closeForcibly();
|
closeForcibly();
|
||||||
|
closeFuture.setClosed();
|
||||||
promise.setFailure(t);
|
promise.setFailure(t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -440,12 +441,12 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
// Close the channel directly to avoid FD leak.
|
// Close the channel directly to avoid FD leak.
|
||||||
closeForcibly();
|
closeForcibly();
|
||||||
|
closeFuture.setClosed();
|
||||||
if (!promise.tryFailure(t)) {
|
if (!promise.tryFailure(t)) {
|
||||||
logger.warn(
|
logger.warn(
|
||||||
"Tried to fail the registration promise, but it is complete already. " +
|
"Tried to fail the registration promise, but it is complete already. " +
|
||||||
"Swallowing the cause of the registration failure:", t);
|
"Swallowing the cause of the registration failure:", t);
|
||||||
}
|
}
|
||||||
closeFuture.setClosed();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -750,14 +751,6 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
*/
|
*/
|
||||||
protected abstract void doDisconnect() throws Exception;
|
protected abstract void doDisconnect() throws Exception;
|
||||||
|
|
||||||
/**
|
|
||||||
* Will be called before the actual close operation will be performed. Sub-classes may override this as the default
|
|
||||||
* is to do nothing.
|
|
||||||
*/
|
|
||||||
protected void doPreClose() throws Exception {
|
|
||||||
// NOOP by default
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Close the {@link Channel}
|
* Close the {@link Channel}
|
||||||
*/
|
*/
|
||||||
@ -834,11 +827,6 @@ public abstract class AbstractChannel extends DefaultAttributeMap implements Cha
|
|||||||
}
|
}
|
||||||
|
|
||||||
boolean setClosed() {
|
boolean setClosed() {
|
||||||
try {
|
|
||||||
doPreClose();
|
|
||||||
} catch (Exception e) {
|
|
||||||
logger.warn("doPreClose() raised an exception.", e);
|
|
||||||
}
|
|
||||||
return super.trySuccess();
|
return super.trySuccess();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -198,25 +198,19 @@ public class LocalChannel extends AbstractChannel {
|
|||||||
doClose();
|
doClose();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doPreClose() throws Exception {
|
|
||||||
if (state > 2) {
|
|
||||||
// Closed already
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update all internal state before the closeFuture is notified.
|
|
||||||
if (localAddress != null) {
|
|
||||||
if (parent() == null) {
|
|
||||||
LocalChannelRegistry.unregister(localAddress);
|
|
||||||
}
|
|
||||||
localAddress = null;
|
|
||||||
}
|
|
||||||
state = 3;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doClose() throws Exception {
|
protected void doClose() throws Exception {
|
||||||
|
if (state <= 2) {
|
||||||
|
// Update all internal state before the closeFuture is notified.
|
||||||
|
if (localAddress != null) {
|
||||||
|
if (parent() == null) {
|
||||||
|
LocalChannelRegistry.unregister(localAddress);
|
||||||
|
}
|
||||||
|
localAddress = null;
|
||||||
|
}
|
||||||
|
state = 3;
|
||||||
|
}
|
||||||
|
|
||||||
LocalChannel peer = this.peer;
|
LocalChannel peer = this.peer;
|
||||||
if (peer != null && peer.isActive()) {
|
if (peer != null && peer.isActive()) {
|
||||||
peer.unsafe().close(unsafe().voidPromise());
|
peer.unsafe().close(unsafe().voidPromise());
|
||||||
|
@ -93,22 +93,14 @@ public class LocalServerChannel extends AbstractServerChannel {
|
|||||||
state = 1;
|
state = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void doPreClose() throws Exception {
|
|
||||||
if (state > 1) {
|
|
||||||
// Closed already.
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update all internal state before the closeFuture is notified.
|
|
||||||
LocalChannelRegistry.unregister(localAddress);
|
|
||||||
localAddress = null;
|
|
||||||
state = 2;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void doClose() throws Exception {
|
protected void doClose() throws Exception {
|
||||||
// All internal state was updated already at doPreClose().
|
if (state <= 1) {
|
||||||
|
// Update all internal state before the closeFuture is notified.
|
||||||
|
LocalChannelRegistry.unregister(localAddress);
|
||||||
|
localAddress = null;
|
||||||
|
state = 2;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
Reference in New Issue
Block a user