GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — SslHandler doesn't release buffered outbound messages (removed from pendingUnencryptedWrites) or complete the corresponding ChannelPromises if wrap() throws an exception · Issue #14644 · netty/netty

SslHandler doesn't release buffered outbound messages (removed from pendingUnencryptedWrites) or complete the corresponding ChannelPromises if wrap() throws an exception #14644

New issue
Copy link
New issue
Copy link
Closed
#14647
Closed
SslHandler doesn't release buffered outbound messages (removed from pendingUnencryptedWrites) or complete the corresponding ChannelPromises if wrap() throws an exception#14644
#14647
Copy link
Milestone
4.1.117.Final

Description

@devromik
devromik
opened on Jan 9, 2025
Issue body actions

Expected behavior

SslHandler should release buffered outbound messages (removed from pendingUnencryptedWrites) and complete the corresponding ChannelPromises, even if wrap() at SslHandler.java#L869 throws an exception.

Actual behavior

SslHandler doesn't release buffered outbound messages (removed from pendingUnencryptedWrites) or complete the corresponding ChannelPromises if wrap() at SslHandler.java#L869 throws an exception.

Steps to reproduce

It's difficult to reproduce this issue automatically, as it depends on particular concurrency conditions. We used the following approach:

  1. In debug mode, start any HTTP (WebSocket in our case) server that uses OpenSSL for secure connections (specifically, ReferenceCountedOpenSslEngine).
  2. Add a breakpoint at ReferenceCountedOpenSslEngine.java#L928.
  3. Send an outbound message (in our case, a TextWebSocketFrame)
  4. When the control flow hits the breakpoint, set pendingException = new RuntimeException. if you are using IDEA, you can set the variable's value during debug. In our environment, for example, we see the following exception instead: OpenSslException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT

As a result, you should get a stack trace similar to the following one:

This pending inbound exception ReferenceCountedOpenSslEngine.java#L213:

i.n.h.s.ReferenceCountedOpenSslEngine$OpenSslException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT
	at i.n.h.s.ReferenceCountedOpenSslEngine.newSSLExceptionForError(ReferenceCountedOpenSslEngine.java:1389)
	at i.n.h.s.ReferenceCountedOpenSslEngine.needWrapAgain(ReferenceCountedOpenSslEngine.java:1375)
	at i.n.h.s.ReferenceCountedOpenSslEngine.sslReadErrorResult(ReferenceCountedOpenSslEngine.java:1406)
	at i.n.h.s.ReferenceCountedOpenSslEngine.unwrap(ReferenceCountedOpenSslEngine.java:1337)
	at i.n.h.s.ReferenceCountedOpenSslEngine.unwrap(ReferenceCountedOpenSslEngine.java:1438)
	at i.n.h.s.ReferenceCountedOpenSslEngine.unwrap(ReferenceCountedOpenSslEngine.java:1481)
	at i.n.h.s.SslHandler$SslEngineType$1.unwrap(SslHandler.java:224)
	at i.n.h.ssl.SslHandler.unwrap(SslHandler.java:1445)
	at i.n.h.ssl.SslHandler.decodeNonJdkCompatible(SslHandler.java:1349)
	at i.n.h.ssl.SslHandler.decode(SslHandler.java:1389)
	at i.n.h.c.ByteToMessageDecoder.decodeRemovalReentryProtection(ByteToMessageDecoder.java:530)
	at i.n.h.c.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:469)
	at i.n.h.c.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:290)
	at i.n.c.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:444)
	at i.n.c.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at i.n.c.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:412)
	at i.n.c.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1410)
	at i.n.c.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:440)
	at i.n.c.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:420)
	at i.n.c.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:919)
	at i.n.c.e.AbstractEpollStreamChannel$EpollStreamUnsafe.epollInReady(AbstractEpollStreamChannel.java:801)
	at i.n.c.e.EpollEventLoop.processReady(EpollEventLoop.java:501)
	at i.n.c.e.EpollEventLoop.run(EpollEventLoop.java:399)
	... 4 common frames omitted

caused the following outbound exception ReferenceCountedOpenSslEngine.java#L934:

Wrapped by: j.n.ssl.SSLException: io.netty.handler.ssl.ReferenceCountedOpenSslEngine$OpenSslException: error:1e000065:Cipher functions:OPENSSL_internal:BAD_DECRYPT
	at i.n.h.s.ReferenceCountedOpenSslEngine.wrap(ReferenceCountedOpenSslEngine.java:934)
	at j.net.ssl.SSLEngine.wrap(SSLEngine.java:522)
	at i.n.h.ssl.SslHandler.wrap(SslHandler.java:1131)
	at i.n.h.ssl.SslHandler.wrap(SslHandler.java:869)
	at i.n.h.ssl.SslHandler.wrapAndFlush(SslHandler.java:822)
	at i.n.h.ssl.SslHandler.flush(SslHandler.java:803)
	at i.n.c.AbstractChannelHandlerContext.invokeFlush0(AbstractChannelHandlerContext.java:941)
	... 91 common frames omitted

Notice that ReferenceCountedOpenSslEngine.java#L934 leads to exiting the control flow at SslHandler.java#L869.

The problem is that this exit happens after the messages (and their promises) have already been removed from pendingUnencryptedWrites at SslHandler.java#L840 but before they are actually written to the next handler in the pipeline (i.e., before the next handler takes responsibility for releasing them and completing the promises) at SslHandler.java#L887. As a result, these messages are never released, and their corresponding promises are never completed.

Netty version

4.1.109.Final

JVM version (e.g. java -version)

openjdk version "11.0.20.1" 2023-08-22 LTS
OpenJDK Runtime Environment Corretto-11.0.20.9.1 (build 11.0.20.1+9-LTS)
OpenJDK 64-Bit Server VM Corretto-11.0.20.9.1 (build 11.0.20.1+9-LTS, mixed mode)

OS version (e.g. uname -a)

22.6.0 Darwin Kernel Version 22.6.0: Sun Dec 17 22:12:45 PST 2023; RELEASE_ARM64_T6000 arm64

Activity

  1. devromik commented on Jan 10, 2025

    @devromik
    devromik
    on Jan 10, 2025
    Author
    More actions

    I'm not sure that messages always remain unreleased, but ChannelPromises are not completed.

  2. normanmaurer
    added this to the 4.1.117.Final milestone on Jan 10, 2025
  3. normanmaurer commented on Jan 10, 2025

    @normanmaurer
    normanmaurer
    on Jan 10, 2025
    Member
    More actions

    @devromik thanks for the report... working on a fix as we speak.

    Reacted by Roman Shulnyaev
  4. normanmaurer commented on Jan 10, 2025

    @normanmaurer
    normanmaurer
    on Jan 10, 2025
    Member
    More actions

    @devromik PTAL #14647

    Reacted by Roman Shulnyaev
  5. normanmaurer
    closed this as completedin #14647on Jan 13, 2025
  6. normanmaurer
    closed this as completedin b8e25e0on Jan 13, 2025
  7. normanmaurer
    added 4 commits that reference this issue on Jan 13, 2025

    SslHandler: Ensure buffers are never leaked when wrap(...) produce SS… (

    8eb6929

    SslHandler: Ensure buffers are never leaked when wrap(...) produce SS… (

    f176672

    SslHandler: Ensure buffers are never leaked when wrap(...) produce SS… (

    c0e3d27

    SslHandler: Ensure buffers are never leaked when wrap(...) produce SS… (

    f2ef154
  8. pull
    added a commit that references this issue on Jan 13, 2025

    SslHandler: Ensure buffers are never leaked when wrap(...) produce SS… (

    b8e25e0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      • 4.1.117.Final

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.