Use explicit SSLContext for better socket handling on Windows/MSYS2

Replace tuple-based ssl_context with explicit ssl.SSLContext creation using
PROTOCOL_TLS_SERVER and load_cert_chain(). This follows Python ssl module
best practices and may handle socket configuration more robustly on MSYS2
where sockets may default to non-blocking mode.

The tuple shortcut (cert, key) internally creates an SSLContext, but using
an explicit SSLContext gives us better control and follows the documented
approach for server-side SSL. This may help with the errno 11 (Resource
temporarily unavailable) issue on Windows/MSYS2.

If this doesn't resolve the issue, we'll need to investigate more invasive
solutions like wrapping Werkzeug's socket creation.

Co-Authored-By: Thiago Alves <thiagoralves@gmail.com>
This commit is contained in:
Devin AI
2025-10-08 20:12:41 +00:00
parent 51183f5df3
commit e52d48c5cf

View File

@@ -2672,7 +2672,8 @@ def run_https():
print("Credentials already generated!")
try:
context = (str(CERT_FILE), str(KEY_FILE))
context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
context.load_cert_chain(certfile=str(CERT_FILE), keyfile=str(KEY_FILE))
app_restapi.run(debug=False, host='0.0.0.0', threaded=True, port=8443, ssl_context=context)
except KeyboardInterrupt as e:
print(f"Exiting OpenPLC Webserver...{e}")