Skip to content

ssl: keep original SSLContext alive after servername_cb - #1090

Closed
rhenium wants to merge 1 commit into
ruby:masterfrom
rhenium:ky/ssl-mark-orig-sslctx
Closed

ssl: keep original SSLContext alive after servername_cb#1090
rhenium wants to merge 1 commit into
ruby:masterfrom
rhenium:ky/ssl-mark-orig-sslctx

Conversation

@rhenium

@rhenium rhenium commented Aug 5, 2026

Copy link
Copy Markdown
Member

Keep the original SSLContext in a separate instance variable to prevent it from being GC'ed.

When the SNI callback accepts the provided server name, it may replace the SSL_CTX with SSL_set_SSL_CTX() and update SSLSocket#context. However, despite its name, SSL_set_SSL_CTX() does not use all parameters from the new SSL_CTX. In particular, callbacks set by the original SSL_CTX remain in use and therefore require the corresponding SSLContext object to stay alive.


Noticed while reviewing #1089.

Keep the original SSLContext in a separate instance variable to prevent
it from being GC'ed.

When the SNI callback accepts the provided server name, it may replace
the SSL_CTX with SSL_set_SSL_CTX() and update SSLSocket#context.
However, despite its name, SSL_set_SSL_CTX() does not use all
parameters from the new SSL_CTX. In particular, callbacks set by the
original SSL_CTX remain in use and therefore require the corresponding
SSLContext object to stay alive.
@rhenium

rhenium commented Aug 6, 2026

Copy link
Copy Markdown
Member Author

This turned out not to be needed for now, so I'm closing this.

@rhenium rhenium closed this Aug 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant