Fix SSL configuration ignored for non-primary apps in multi-serve#3140
Open
worksbyfriday wants to merge 1 commit intosanic-org:mainfrom
Open
Fix SSL configuration ignored for non-primary apps in multi-serve#3140worksbyfriday wants to merge 1 commit intosanic-org:mainfrom
worksbyfriday wants to merge 1 commit intosanic-org:mainfrom
Conversation
When serving multiple apps via Sanic.serve(), SSL configuration for non-primary apps was silently dropped. The SSL context was stripped from all apps' server_info.settings during serialization for multiprocessing, and only the primary app's SSL was restored on the worker side. Now the SSL configuration for each app is preserved in server_info by converting SSLContext objects to their serializable dict form (SanicSSLContext.sanic) before passing through multiprocessing. On the worker side, per-app SSL dicts are loaded into proper SSL contexts for each app's server_info. Fixes sanic-org#3131 Co-Authored-By: Claude Opus 4.6 <[email protected]>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Fixes #3131
When serving multiple apps via
Sanic.serve(), the SSL configuration for non-primary apps was silently ignored — secondary apps were served over HTTP instead of HTTPS.Root Cause
The SSL configuration flow had a gap for non-primary apps:
Sanic.serve()stripped SSL from all apps'server_info.settingsduring serialization for multiprocessing (sinceSSLContextobjects can't be pickled)kwargs["ssl"]worker_serve()only restored SSL to the primary app's server_infoFix
In
startup.py: Instead of stripping SSL entirely, convertSanicSSLContextto its serializable dict form (sanicattribute) and keep it in each app'sserver_info.settings. Raw dict/string SSL values are passed through as-is.In
serve.py: After the existing primary-app SSL loading, iterate through all apps' server_info and load SSL contexts from any serialized SSL dicts that haven't been converted yet.This preserves backward compatibility — the primary app still gets its SSL from the global kwarg, while non-primary apps now get theirs from their own server_info.