Repository navigation
Conversation
concurrency.wsgi_server() always passed spawn=custom_pool to gevent's WSGIServer. st2auth passes no pool, so gevent received spawn=None, which makes it call the request handler synchronously in the hub greenlet. Anything that then has to switch to the hub fails with BlockingSwitchOutError: with pymongo that is opening a new connection and resolving the host through gevent's thread resolver, so POST /tokens returned HTTP 500 whenever the connection pool needed a new connection. st2api and st2stream always pass a pool and are not affected. Only pass spawn when a pool was given, so gevent spawns a greenlet per request. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
jk464
force-pushed
the
gevent-st2auth-fix
branch
from
December 1, 2026 14:18
2d8024a to
4014c2e
Compare
jk464
marked this pull request as ready for review
December 1, 2026 14:24
st2auth wrapped its listening socket with concurrency.wrap_ssl() and handed the SSLSocket to wsgi_server(). gevent's WSGIServer requires a plain listening socket and does the TLS handshake itself, per accepted connection, so with [auth] use_ssl = True st2auth crashed at startup with "TypeError: Expected a regular socket, not SSLSocket". wsgi_server() now takes certfile and keyfile. Under eventlet it still wraps the socket with eventlet.wrap_ssl(); under gevent it passes an ssl_context to WSGIServer. st2auth passes the files instead of wrapping the socket. The HTTPS tests verify the server certificate: the client trusts only the fixture CA and checks the host name, and there are negative tests for an untrusted CA and a wrong host name (both must raise SSLCertVerificationError). They run on both gevent and eventlet. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
jk464
force-pushed
the
gevent-st2auth-fix
branch
from
December 4, 2026 12:24
4014c2e to
7ba9eec
Compare
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.
Problem
Two independent bugs make
st2authunusable under gevent.1. HTTP 500 on
POST /tokens(BlockingSwitchOutError)concurrency.wsgi_server()always passedspawn=custom_poolto gevent'sWSGIServer.st2apiandst2streamalways pass a pool, butst2authdoes not, so gevent receivedspawn=None. Withspawn=Nonegevent calls the request handler synchronously in the hub greenlet. Anything that then has to switch to the hub fails withBlockingSwitchOutError. With pymongo that is opening a new connection and resolving the host through gevent's thread resolver, soPOST /tokensreturned HTTP 500 whenever the connection pool needed a new connection.2. Crash on startup with
[auth] use_ssl = Truegevent's
WSGIServerneeds a plain listening socket and does the TLS handshake itself, per accepted connection.st2authpre-wrapped the listening socket withconcurrency.wrap_ssl(), so it crashed withTypeError: Expected a regular socket, not SSLSocket.Changes
Two commits, one per fix:
wsgi_server()only passesspawnto gevent when a pool was given, so gevent spawns a greenlet per request.wsgi_server()takescertfileandkeyfile. Under eventlet it still wraps the socket witheventlet.wrap_ssl(). Under gevent it passes anssl_contexttoWSGIServer.st2authnow passes the files instead of wrapping the socket. A note onwrap_ssl()says not to use it for a WSGI server's listening socket.Both have a
CHANGELOG.rstentry.Tests
New
st2common/tests/unit/test_concurrency.py, which runswsgi_server()for plain HTTP (with and without a custom pool) and HTTPS, plus a check that a plain HTTP client does not take the TLS server down. The app handler sleeps, so it fails if the request runs in the hub greenlet.BlockingSwitchOutError, SSLWRONG_VERSION_NUMBER).Verification
Both bugs were reproduced against an
st2auth3.10dev build on Python 3.12 with gevent 26.8 and a TLS-only MongoDB, in addition to the unit tests above.🤖 Generated with Claude Code