GeezerVison is showing github.com — JVM SIGSEGV in jni_CallIntMethod during ReferenceCountedOpenSslEngine.unwrap / SSL.readFromSSL (netty-tcnative 2.0.77.Final, OpenSSL, netty 4.2.15.Final) · Issue #998 · netty/netty-tcnative
JVM SIGSEGV in jni_CallIntMethod during ReferenceCountedOpenSslEngine.unwrap / SSL.readFromSSL (netty-tcnative 2.0.77.Final, OpenSSL, netty 4.2.15.Final) #998DescriptionExpected behavior
The JVM process continues running; TLS reads on a Netty NIO event-loop thread should not crash the process.
Actual behavior
The JVM crashed with a native SIGSEGV (null pointer dereference) inside jni_CallIntMethod, called from the netty-tcnative native library while servicing io.netty.internal.tcnative.SSL.readFromSSL on a Netty NIO event-loop thread that was decoding TLS data via SslHandler/ReferenceCountedOpenSslEngine.
Crashing thread's native + Java stack (top-most frame first):
V [libjvm.so+0x9c06e6] jni_CallIntMethod+0xf6
C [libnetty_tcnative_linux_x86_64<random-suffix>.so+0x12d40]
J io.netty.internal.tcnative.SSL.readFromSSL(JJI)I
J io.netty.handler.ssl.ReferenceCountedOpenSslEngine.unwrap([Ljava/nio/ByteBuffer;II[Ljava/nio/ByteBuffer;II)Ljavax/net/ssl/SSLEngineResult;
J io.netty.handler.ssl.SslHandler$SslEngineType$1.unwrap(Lio/netty/handler/ssl/SslHandler;Lio/netty/buffer/ByteBuf;ILio/netty/buffer/ByteBuf;)Ljavax/net/ssl/SSLEngineResult;
J io.netty.handler.ssl.SslHandler.unwrap(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;I)I
J io.netty.handler.ssl.SslHandler.decode(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;Ljava/util/List;)V
J io.netty.handler.codec.ByteToMessageDecoder.channelRead(Lio/netty/channel/ChannelHandlerContext;Ljava/lang/Object;)V
J io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(Ljava/lang/Object;)Lio/netty/channel/ChannelHandlerContext;
J io.netty.handler.timeout.IdleStateHandler.channelRead(Lio/netty/channel/ChannelHandlerContext;Ljava/lang/Object;)V
J io.netty.channel.nio.NioIoHandler.processSelectedKeysOptimized()I
J io.netty.channel.SingleThreadIoEventLoop.runIo()I
j io.netty.channel.SingleThreadIoEventLoop.run()V+31
j io.netty.util.concurrent.SingleThreadEventExecutor$5.run()V+93
j io.netty.util.internal.ThreadExecutorMap$2.run()V+12
j java.lang.Thread.runWith(Ljava/lang/Object;Ljava/lang/Runnable;)V+5 [email protected]
j java.lang.Thread.run()V+19 [email protected]
siginfo shows si_code=1 (SEGV_MAPERR), si_addr=0x0 — a dereference of address 0.
Several registers feeding the crashing jni_CallIntMethod call are also zero (RDX, RSI, R11, R14, R15), consistent with a null jobject/jmethodID (or an already-freed native handle) being passed from the tcnative native code into the JNI call it makes back into the JVM while inside SSL_read.
Steps to reproduce
Not currently reproducible on demand — this occurred once in a long-running production process after ~21 minutes of uptime, on a Netty client connection performing mutual-TLS (client-cert auth) reads. No minimal repro yet; opening this primarily to check whether it's a known failure mode and to share the native crash data in case it's useful.
Netty version
4.2.15.Final
JVM version (e.g java -version)
OpenJDK 64-Bit Server VM (21.0.11+11-LTS), OpenJDK Runtime Environment (21.0.11+11) (build 21.0.11+11-LTS)
OS version (e.g uname -a)
Linux 6.6.141-generic x86_64, Ubuntu 24.04.4 LTS
JVM arguments (e.g -Xmx1G ...)
Relevant native/TLS-affecting flags: -Dio.netty.recycler.maxCapacityPerThread=0
Other component versions
netty-tcnative-classes-2.0.77.Final
netty-tcnative native artifact 2.0.77.Final (OpenSSL variant) for linux-x86_64
- Dynamically linked TLS libs on the host:
libssl.so.3 / libcrypto.so.3 (OpenSSL 3.x)
Contextual information
- TLS 1.2/1.3, mutual TLS (client certificate auth) enabled, cipher suites
TLS_AES_256_GCM_SHA384, TLS_AES_128_GCM_SHA256.
- Multiple Netty client event-loop threads with active TLS connections were running concurrently in the process at crash time.
- This is running inside a larger Java server product; the hs_err file we're attaching has had product-internal paths, an internal secret token, and internal service configuration redacted — none of that is believed relevant to the crash, but flagging it in case anything looks incomplete.
Crash header
A fatal error has been detected by the Java Runtime Environment:
SIGSEGV (0xb) at pc=0x0000779339fc06e6, pid=<redacted>, tid=6036
JRE version: OpenJDK Runtime Environment (21.0.11+11) (build 21.0.11+11-LTS)
Java VM: OpenJDK 64-Bit Server VM (21.0.11+11-LTS, mixed mode, tiered,
compressed oops, compressed class ptrs, g1 gc, linux-amd64)
Problematic frame:
V [libjvm.so+0x9c06e6] jni_CallIntMethod+0xf6
Host: Intel(R) Xeon(R) Gold 6330 CPU @ 2.00GHz, 6 cores, 23G, Ubuntu 24.04.4 LTS
elapsed time: 1273.610465 seconds (0d 0h 21m 13s) before crash
Crashing thread and native/Java stack
Current thread: JavaThread "client-0" [_thread_in_vm, id=6036]
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
V [libjvm.so+0x9c06e6] jni_CallIntMethod+0xf6
C [libnetty_tcnative_linux_x86_64<random-suffix>.so+0x12d40]
J io.netty.internal.tcnative.SSL.readFromSSL(JJI)I
J io.netty.handler.ssl.ReferenceCountedOpenSslEngine.unwrap([Ljava/nio/ByteBuffer;II[Ljava/nio/ByteBuffer;II)Ljavax/net/ssl/SSLEngineResult;
J io.netty.handler.ssl.SslHandler$SslEngineType$1.unwrap(Lio/netty/handler/ssl/SslHandler;Lio/netty/buffer/ByteBuf;ILio/netty/buffer/ByteBuf;)Ljavax/net/ssl/SSLEngineResult;
J io.netty.handler.ssl.SslHandler.unwrap(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;I)I
J io.netty.handler.ssl.SslHandler.decode(Lio/netty/channel/ChannelHandlerContext;Lio/netty/buffer/ByteBuf;Ljava/util/List;)V
J io.netty.handler.codec.ByteToMessageDecoder.channelRead(Lio/netty/channel/ChannelHandlerContext;Ljava/lang/Object;)V
J io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(Ljava/lang/Object;)Lio/netty/channel/ChannelHandlerContext;
J io.netty.handler.timeout.IdleStateHandler.channelRead(Lio/netty/channel/ChannelHandlerContext;Ljava/lang/Object;)V
J io.netty.channel.nio.NioIoHandler.processSelectedKeysOptimized()I
J io.netty.channel.SingleThreadIoEventLoop.runIo()I
j io.netty.channel.SingleThreadIoEventLoop.run()V+31
j io.netty.util.concurrent.SingleThreadEventExecutor$5.run()V+93
j io.netty.util.internal.ThreadExecutorMap$2.run()V+12
j java.lang.Thread.runWith(Ljava/lang/Object;Ljava/lang/Runnable;)V+5 [email protected]
j java.lang.Thread.run()V+19 [email protected]
v ~StubRoutines::call_stub
siginfo / registers
siginfo: si_signo: 11 (SIGSEGV), si_code: 1 (SEGV_MAPERR), si_addr: 0x0000000000000000
RAX=0x0000779313eb3eb0, RBX=0x00001e7d6f94c0a0, RCX=0x00007793351c35b0, RDX=0x0000000000000000
RSP=0x0000779313eb3d30, RBP=0x0000779313eb3ea0, RSI=0x0000000000000000, RDI=0x00001e7d6f94c460
R8 =0x0000779335d6a290, R9 =0x0000779335d6a2a0, R10=0x000077933ad43060, R11=0x0000000000000000
R12=0x00001e7d6f94c460, R13=0x0000779313eb3d80, R14=0x0000000000000000, R15=0x0000000000000000
RIP=0x0000779339fc06e6, EFLAGS=0x0000000000010246
TRAPNO=0x000000000000000e
Note the null si_addr, and several zeroed registers (RDX, RSI, R11, R14, R15) feeding into
the crashing jni_CallIntMethod call — consistent with a null jobject/jmethodID (or a
freed/zeroed native handle) being passed into the JNI call made from inside the tcnative
native library while it is executing SSL_read.
Versions / environment
- Netty:
4.2.15.Final (netty-common/buffer/codec/handler/transport/resolver modules all at this version)
- netty-tcnative:
2.0.77.Final (netty-tcnative-classes-2.0.77.Final.jar +
netty-tcnative-...-linux-x86_64.jar, OpenSSL variant — see note below)
- TLS native libs dynamically linked by the process:
libssl.so.3, libcrypto.so.3
(OpenSSL 3.x, from the OS, i.e. SSL.readFromSSL is going through OpenSSL, not BoringSSL-static)
- JVM: OpenJDK 21.0.11+11 (LTS build; based on BellSoft Liberica per the vendor bug-report URL in the header)
- OS: Ubuntu 24.04.4 LTS, kernel
6.6.141-generic, x86_64
- CPU: Intel Xeon Gold 6330, 6 cores
- Relevant JVM system property set:
-Dio.netty.recycler.maxCapacityPerThread=0
- TLS config in use: TLSv1.3/TLSv1.2, mutual-TLS (client cert auth) enabled,
cipher suites TLS_AES_256_GCM_SHA384, TLS_AES_128_GCM_SHA256
- 4 other Netty client threads following the same
client-N naming pattern were alive
in the process at crash time (see thread dump), suggesting several TLS connections/engines
were active concurrently.
What was redacted from the original hs_err file before sharing
- Full JVM command line /
java_command / java_class_path (contained internal service
names, an internal -Dwrapper.key=... secret token, internal file paths, and ~250 internal
and third-party JAR names/versions unrelated to the crash).
- A private IPv4 address the process was bound to.
- Internal file paths (config/log/keystore/truststore locations, install paths).
- Full 400+ line process memory map, GC heap history, deoptimization event log, and JIT
disassembly listings — omitted as noise not relevant to triaging this crash;
Activitynormanmaurer commented on Aug 18, 2026 Not know already... Will check if I can spot anything. That said please add more details when you get them normanmaurer commented on Aug 18, 2026 @zfrenette can you show me how SslContextBuilder is used to build the context that is used later on ? normanmaurer commented on Aug 19, 2026 This is kind of related #999 zfrenette commented on Aug 19, 2026
@zfrenette can you show me how SslContextBuilder is used to build the context that is used later on ?
Let me share this shortly. Meanwhile, a coworker of mine shared the following TSAN report:
WARNING: ThreadSanitizer: data race
Write of size 8 by thread T2:
#0 ssl_context_cleanup sslcontext.c:126 <- c->verifier = NULL;
#1 netty_internal_tcnative_SSLContext_free
Previous read of size 8 by thread T1:
#0 SSL_cert_verify sslcontext.c:1632 <- CallIntMethod(e, c->verifier, c->verifier_method, ...)
WARNING: ThreadSanitizer: data race (same thing for c->verifier_method, line 128)
[fakeJNI] CallIntMethod #179593: obj=(nil) methodID=0x2002 <<< NULL ARG -- this is exactly
what jni_CallIntMethod dereferences unconditionally in a product JVM build and segfaults on normanmaurer commented on Aug 19, 2026 So it seems like SSLContext.free() is called while the handshake is still in progress. zfrenette commented on Aug 19, 2026
@zfrenette can you show me how SslContextBuilder is used to build the context that is used later on ?
The context is build in the following way:
sslContext = SslContextConstructor.constructSslContext(
false,
parameters.getKeyStoreConfig(),
parameters.getTrustStoreConfig()
);
public static SslContext constructSslContext(
boolean isServer, KeyStoreConfig keyStoreConfig, TrustStoreConfig trustStoreConfig) throws SSLException {
KeyManagerFactory kmf = new ReloadableKeyManagerFactory(keyStoreConfig);
ReloadableTrustManagerFactory tmf = new ReloadableTrustManagerFactory(trustStoreConfig);
SslProvider provider = getSslProvider();
SslContext sslContext;
if (isServer) {
sslContext = SslContextBuilder
.forServer(kmf)
.sslProvider(provider)
.trustManager(tmf)
.build();
} else {
sslContext = SslContextBuilder
.forClient()
.sslProvider(provider)
// Netty 4.2 changed the client default of endpointIdentificationAlgorithm
// from null to "HTTPS" (hostname verification enabled). Explicitly set
// null to preserve the pre-4.2 behavior, where peer identity is asserted
// solely via the configured trust manager. Flip to "HTTPS" only after
// confirming all server certificates carry SANs matching the
// hostnames clients dial.
.endpointIdentificationAlgorithm(null)
.keyManager(kmf)
.trustManager(tmf)
.build();
}
log.debug("Created ssl context {}. isServer {}, type is {}",
sslContext, isServer, sslContext.getClass().getName());
return sslContext;
}
private static SslProvider getSslProvider() {
SslProvider provider = SslProvider.JDK;
if (OpenSsl.isAvailable()) {
provider = SslProvider.OPENSSL;
log.info("Using OpenSSL provider (native): version={}", OpenSsl.versionString());
} else {
log.warn("OpenSSL is NOT available, falling back to JDK SSL. Reason: {}",
OpenSsl.unavailabilityCause() != null ? OpenSsl.unavailabilityCause().getMessage() : "unknown");
if (OpenSsl.unavailabilityCause() != null) {
log.debug("OpenSSL unavailable - full stack trace:", OpenSsl.unavailabilityCause());
}
}
return provider;
}
zfrenette commented on Aug 19, 2026
This is kind of related #999
On the surface, it looks like this would address the issue observed? normanmaurer commented on Aug 19, 2026 @zfrenette yes... that said I would like to understand how it is even possible to have free called while we still doing the handshake . Reacted by Zachary Frenette normanmaurer commented on Aug 19, 2026 @zfrenette so after you have the context how do you create the SslHandler ? zfrenette commented on Aug 19, 2026
@zfrenette so after you have the context how do you create the SslHandler ?
I think that this is what you are asking for:
Bootstrap b = new Bootstrap();
b.group(eventLoopGroup);
b.channel(parameters.getSocketType().getChannelClass());
parameters.getNettyChannelOptions().forEach(b::option);
b.handler(getChannelInitializer());
b.option(ChannelOption.CONNECT_TIMEOUT_MILLIS, (int) timeoutConnect);
private ChannelInitializer<Channel> getChannelInitializer() {
return new ChannelInitializer<Channel>() {
@Override
protected void initChannel(@Nonnull Channel ch) throws Exception {
ch.pipeline().addLast(new IdleStateHandler(parameters.getIdleConnectionTimeout(),
parameters.getKeepAlivePeriod(), 0));
if (parameters.isTlsEnabled()) {
ch.pipeline().addLast("ssl", sslContext.newHandler(ch.alloc()));
}
ch.pipeline().addLast(new LengthFieldPrepender(4));
ch.pipeline().addLast(new LengthFieldBasedFrameDecoder(Integer.MAX_VALUE,
0, 4, 0,
4));
if (parameters.isSaslPlainTextEnabled()) {
PlainTextSaslNettyClient saslNettyClient =
SaslUtils.enableSaslPlainText(parameters.getUsernameFile(),
parameters.getPasswordFile());
ch.pipeline().addLast("sasl/plain-text", saslNettyClient);
}
ch.pipeline().addLast(new NettyMessageDecoder());
ch.pipeline().addLast(new NettyMessageEncoder());
ch.pipeline().addLast(new ClientHandshakeHandler(parameters.getClientId(),
node.getNodeId(), parameters.getHandshakeTimeout()));
ch.pipeline().addLast(NettyClientRouter.this);
}
};
}
normanmaurer commented on Aug 19, 2026 zfrenette commented on Aug 19, 2026
@zfrenette yes that's it.. Thanks.
Perhaps one more datapoint for you - NettyClientRouter::stop has the following:
@Override
public void stop() {
log.debug("stop: Shutting down router for {}", node);
shutdown = true;
connectionFuture.completeExceptionally(new NetworkException("Router stopped", node));
if (channel != null && channel.isOpen()) {
channel.close().syncUninterruptibly();
}
if (sslContext instanceof io.netty.util.ReferenceCounted) {
((io.netty.util.ReferenceCounted) sslContext).release();
log.debug("stop: Released SslContext {} for node {}", sslContext, node);
}
}
Can the explicit call to release() cause an issue here? normanmaurer commented on Aug 19, 2026 @zfrenette yes! You should not do this by yourself. Reacted by Zachary Frenette zfrenette commented on Aug 19, 2026
@zfrenette yes! You should not do this by yourself.
We had seen some leaked resources in a heap dump (perhaps just being a symptom of another issue that we have missed), and had observed the following in the docs:
Instances of this class must be [released](https://netty.io/4.1/api/io/netty/handler/ssl/ReferenceCountedOpenSslContext.html#release--) or else native memory will leak!
But also observing this:
Instances of this class must not be released before any [ReferenceCountedOpenSslEngine](https://netty.io/4.1/api/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.html) which depends upon the instance of this class is released. Otherwise if any method of [ReferenceCountedOpenSslEngine](https://netty.io/4.1/api/io/netty/handler/ssl/ReferenceCountedOpenSslEngine.html) is called which uses this class's JNI resources the JVM may crash.
normanmaurer commented on Aug 19, 2026 Yes and thats the problem here... You release it before the ReferenceCountedOpenSslEngine is released. So if you want to release it by yourself you will need to ensure that all the engines are already released as well. normanmaurer commented on Aug 19, 2026 Best is to just leave it alone and let the finalizer handle it. normanmaurer commented on Aug 24, 2026 I think we can close this one...
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|