doClose() — netty Function Reference
Architecture documentation for the doClose() function in LocalChannel.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD f1b1c04a_89d4_cfdf_491a_2834d7b50724["doClose()"] 81a44f54_ab3c_5f8b_4522_05c91e5f8eb8["LocalChannel"] f1b1c04a_89d4_cfdf_491a_2834d7b50724 -->|defined in| 81a44f54_ab3c_5f8b_4522_05c91e5f8eb8 6a05c3d0_7239_dcce_dcd4_dc3705127134["doDisconnect()"] 6a05c3d0_7239_dcce_dcd4_dc3705127134 -->|calls| f1b1c04a_89d4_cfdf_491a_2834d7b50724 562d5c11_6ff6_9b17_d006_101ff1054c95["registered()"] 562d5c11_6ff6_9b17_d006_101ff1054c95 -->|calls| f1b1c04a_89d4_cfdf_491a_2834d7b50724 2c83511c_fc90_29cc_5eaa_7b360efc3314["finishPeerRead()"] f1b1c04a_89d4_cfdf_491a_2834d7b50724 -->|calls| 2c83511c_fc90_29cc_5eaa_7b360efc3314 e5e77d83_af4b_40c2_06fb_b37cd74710b7["isActive()"] f1b1c04a_89d4_cfdf_491a_2834d7b50724 -->|calls| e5e77d83_af4b_40c2_06fb_b37cd74710b7 7f95a1bb_b49a_748e_2757_d753b7bb2505["tryClose()"] f1b1c04a_89d4_cfdf_491a_2834d7b50724 -->|calls| 7f95a1bb_b49a_748e_2757_d753b7bb2505 67917219_8f92_90b6_97f7_b6c689224093["releaseInboundBuffers()"] f1b1c04a_89d4_cfdf_491a_2834d7b50724 -->|calls| 67917219_8f92_90b6_97f7_b6c689224093 19db0fc8_1524_a49b_2c8e_8b165b94bc06["close()"] f1b1c04a_89d4_cfdf_491a_2834d7b50724 -->|calls| 19db0fc8_1524_a49b_2c8e_8b165b94bc06 style f1b1c04a_89d4_cfdf_491a_2834d7b50724 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
transport/src/main/java/io/netty/channel/local/LocalChannel.java lines 221–289
@Override
protected void doClose() throws Exception {
final LocalChannel peer = this.peer;
State oldState = state;
try {
if (oldState != State.CLOSED) {
// Update all internal state before the closeFuture is notified.
if (localAddress != null) {
if (parent() == null) {
LocalChannelRegistry.unregister(localAddress);
}
localAddress = null;
}
// State change must happen before finishPeerRead to ensure writes are released either in doWrite or
// channelRead.
state = State.CLOSED;
// Preserve order of event and force a read operation now before the close operation is processed.
if (writeInProgress && peer != null) {
finishPeerRead(peer);
}
ChannelPromise promise = connectPromise;
if (promise != null) {
// Use tryFailure() instead of setFailure() to avoid the race against cancel().
promise.tryFailure(new ClosedChannelException());
connectPromise = null;
}
}
if (peer != null) {
this.peer = null;
// Always call peer.eventLoop().execute() even if peer.eventLoop().inEventLoop() is true.
// This ensures that if both channels are on the same event loop, the peer's channelInActive
// event is triggered *after* this peer's channelInActive event
EventLoop peerEventLoop = peer.eventLoop();
final boolean peerIsActive = peer.isActive();
try {
peerEventLoop.execute(new Runnable() {
@Override
public void run() {
peer.tryClose(peerIsActive);
}
});
} catch (Throwable cause) {
logger.warn("Releasing Inbound Queues for channels {}-{} because exception occurred!",
this, peer, cause);
if (peerEventLoop.inEventLoop()) {
peer.releaseInboundBuffers();
} else {
// inboundBuffers is a SPSC so we may leak if the event loop is shutdown prematurely or
// rejects the close Runnable but give a best effort.
peer.close();
}
PlatformDependent.throwException(cause);
}
}
} finally {
// Release all buffers if the Channel was already registered in the past and if it was not closed before.
if (oldState != null && oldState != State.CLOSED) {
// We need to release all the buffers that may be put into our inbound queue since we closed the Channel
// to ensure we not leak any memory. This is fine as it basically gives the same guarantees as TCP which
// means even if the promise was notified before its not really guaranteed that the "remote peer" will
// see the buffer at all.
releaseInboundBuffers();
}
}
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does doClose() do?
doClose() is a function in the netty codebase, defined in transport/src/main/java/io/netty/channel/local/LocalChannel.java.
Where is doClose() defined?
doClose() is defined in transport/src/main/java/io/netty/channel/local/LocalChannel.java at line 221.
What does doClose() call?
doClose() calls 5 function(s): close, finishPeerRead, isActive, releaseInboundBuffers, tryClose.
What calls doClose()?
doClose() is called by 2 function(s): doDisconnect, registered.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free