safeClose() — netty Function Reference
Architecture documentation for the safeClose() function in SslHandler.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD e7a7ecf5_bbaa_6525_0168_c2a3b76d209d["safeClose()"] d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1["SslHandler"] e7a7ecf5_bbaa_6525_0168_c2a3b76d209d -->|defined in| d8b07a7c_44f8_c4e9_efe8_49bfae7d4af1 22b36647_11f2_7260_1e39_2e07c2db7166["closeOutboundAndChannel()"] 22b36647_11f2_7260_1e39_2e07c2db7166 -->|calls| e7a7ecf5_bbaa_6525_0168_c2a3b76d209d 49028cb7_a127_0716_20ed_4fc1e1c7c988["close()"] e7a7ecf5_bbaa_6525_0168_c2a3b76d209d -->|calls| 49028cb7_a127_0716_20ed_4fc1e1c7c988 fb8059d2_577d_b68e_bcd7_2caea40df1e0["addCloseListener()"] e7a7ecf5_bbaa_6525_0168_c2a3b76d209d -->|calls| fb8059d2_577d_b68e_bcd7_2caea40df1e0 f0428da0_54a3_9dcb_eefb_1da6c347f719["run()"] e7a7ecf5_bbaa_6525_0168_c2a3b76d209d -->|calls| f0428da0_54a3_9dcb_eefb_1da6c347f719 style e7a7ecf5_bbaa_6525_0168_c2a3b76d209d fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
handler/src/main/java/io/netty/handler/ssl/SslHandler.java lines 2335–2406
private void safeClose(
final ChannelHandlerContext ctx, final ChannelFuture flushFuture,
final ChannelPromise promise) {
if (!ctx.channel().isActive()) {
ctx.close(promise);
return;
}
final Future<?> timeoutFuture;
if (!flushFuture.isDone()) {
long closeNotifyTimeout = closeNotifyFlushTimeoutMillis;
if (closeNotifyTimeout > 0) {
// Force-close the connection if close_notify is not fully sent in time.
timeoutFuture = ctx.executor().schedule(new Runnable() {
@Override
public void run() {
// May be done in the meantime as cancel(...) is only best effort.
if (!flushFuture.isDone()) {
logger.warn("{} Last write attempt timed out; force-closing the connection.",
ctx.channel());
addCloseListener(ctx.close(ctx.newPromise()), promise);
}
}
}, closeNotifyTimeout, TimeUnit.MILLISECONDS);
} else {
timeoutFuture = null;
}
} else {
timeoutFuture = null;
}
// Close the connection if close_notify is sent in time.
flushFuture.addListener(f -> {
if (timeoutFuture != null) {
timeoutFuture.cancel(false);
}
final long closeNotifyReadTimeout = closeNotifyReadTimeoutMillis;
if (closeNotifyReadTimeout <= 0) {
// Trigger the close in all cases to make sure the promise is notified
// See https://github.com/netty/netty/issues/2358
addCloseListener(ctx.close(ctx.newPromise()), promise);
} else {
final Future<?> closeNotifyReadTimeoutFuture;
if (!sslClosePromise.isDone()) {
closeNotifyReadTimeoutFuture = ctx.executor().schedule(new Runnable() {
@Override
public void run() {
if (!sslClosePromise.isDone()) {
logger.debug(
"{} did not receive close_notify in {}ms; force-closing the connection.",
ctx.channel(), closeNotifyReadTimeout);
// Do the close now...
addCloseListener(ctx.close(ctx.newPromise()), promise);
}
}
}, closeNotifyReadTimeout, TimeUnit.MILLISECONDS);
} else {
closeNotifyReadTimeoutFuture = null;
}
// Do the close once the we received the close_notify.
sslClosePromise.addListener(future -> {
if (closeNotifyReadTimeoutFuture != null) {
closeNotifyReadTimeoutFuture.cancel(false);
}
addCloseListener(ctx.close(ctx.newPromise()), promise);
});
}
});
}
Domain
Subdomains
Called By
Source
Frequently Asked Questions
What does safeClose() do?
safeClose() is a function in the netty codebase, defined in handler/src/main/java/io/netty/handler/ssl/SslHandler.java.
Where is safeClose() defined?
safeClose() is defined in handler/src/main/java/io/netty/handler/ssl/SslHandler.java at line 2335.
What does safeClose() call?
safeClose() calls 3 function(s): addCloseListener, close, run.
What calls safeClose()?
safeClose() is called by 1 function(s): closeOutboundAndChannel.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free