Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python atexit behaviour with openssl lib and lazy-apps #2700

Open
nacho692 opened this issue Jan 8, 2025 · 0 comments
Open

python atexit behaviour with openssl lib and lazy-apps #2700

nacho692 opened this issue Jan 8, 2025 · 0 comments

Comments

@nacho692
Copy link

nacho692 commented Jan 8, 2025

I have a uWSGI server with required lazy-apps = true. When the process exits I need to do some cleanup which involves generating http requests but it errors out when creating SSL context.

  • uWSGI 2.0.28 (64bit)
  • Python version: 3.11.11

Disabling lazy-apps seems to fix the problem.

I was able to generate a min version that reproduces the issue:

[uwsgi]
strict = true
vacuum = true
master = true
die-on-term = true
need-app = true
enable-threads = true
single-interpreter = true
lazy-apps = true
#skip-atexit-teardown = true
wsgi-file=app_api.py

auto-procname = true
procname-prefix-spaced = app
workers = 1

socket = /tmp/app_api.sock
chmod-socket = 664
import falcon
import atexit
import ssl

def get_app():

    def exith():
        print('Exiting...')
        ctx = ssl.create_default_context()
        print(ctx)

    atexit.register(exith)
    ctx = ssl.create_default_context()
    print(ctx)
    app = falcon.App()
    return app

application = get_app()
spawned uWSGI master process (pid: 13998)
spawned uWSGI worker 1 (pid: 13999, cores: 1)
<ssl.SSLContext object at 0x7374fb3eb260>
WSGI app 0 (mountpoint='') ready in 1 seconds on interpreter 0x7374fcf87478 pid: 13999 (default app)
SIGINT/SIGTERM received...killing workers...
Exiting...
Exception ignored in atexit callback: <function get_app.<locals>.exith at 0x7374fc120400>
Traceback (most recent call last):
  File "app_api.py", line 9, in exith
    ctx = ssl.create_default_context()
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ssl.py", line 761, in create_default_context
    context = SSLContext(PROTOCOL_TLS_CLIENT)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/lib/python3.11/ssl.py", line 500, in __new__
    self = _SSLContext.__new__(cls, protocol)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
ssl.SSLError: unknown error (_ssl.c:3098)
worker 1 buried after 1 seconds
goodbye to uWSGI.

Perhaps this is related to #1969?

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

No branches or pull requests

1 participant