Skip to content

Fix SSL configuration ignored for non-primary apps in multi-serve#3140

Open
worksbyfriday wants to merge 1 commit intosanic-org:mainfrom
worksbyfriday:fix-multi-app-ssl-3131
Open

Fix SSL configuration ignored for non-primary apps in multi-serve#3140
worksbyfriday wants to merge 1 commit intosanic-org:mainfrom
worksbyfriday:fix-multi-app-ssl-3131

Conversation

@worksbyfriday
Copy link

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:

  1. Sanic.serve() stripped SSL from all apps' server_info.settings during serialization for multiprocessing (since SSLContext objects can't be pickled)
  2. Only the primary app's SSL was passed as a global kwargs["ssl"]
  3. worker_serve() only restored SSL to the primary app's server_info

Fix

In startup.py: Instead of stripping SSL entirely, convert SanicSSLContext to its serializable dict form (sanic attribute) and keep it in each app's server_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.

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]>
@worksbyfriday worksbyfriday requested a review from a team as a code owner February 18, 2026 13:25
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.

SSL configuration ignored for non-primary apps

1 participant