fix: make_safe_connect crashes on Windows due to missing uvloop#5631
Open
stayliv3 wants to merge 2 commits into
Open
fix: make_safe_connect crashes on Windows due to missing uvloop#5631stayliv3 wants to merge 2 commits into
stayliv3 wants to merge 2 commits into
Conversation
On Windows where uvloop is unavailable, make_safe_connect() raises ModuleNotFoundError, breaking URL-based file input for any service with Path/Image parameters. This leaves Windows deployments without SSRF protection entirely. Add a fallback implementation using socket.getaddrinfo patching that provides equivalent SSRF protection (blocking private/loopback/link-local IPs) on platforms without uvloop. Tested on: - Windows 10/11 + Python 3.12: SSRF now correctly blocked (was 500 crash) - Linux + uvloop 0.22.1: Existing behavior unchanged
For more information, see https://pre-commit.ci
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
make_safe_connect()insrc/bentoml/_internal/utils/uri.pyunconditionally importsuvloop(line 69), which is unavailable on Windows. This causes aModuleNotFoundErrorcrash on any BentoML service that accepts file/image URL inputs, leaving Windows deployments with zero SSRF protection.Impact
ModuleNotFoundError: No module named uvloopin server logsFix
Added a
try/except ImportErroraround the uvloop import with a fallback implementation:socket.getaddrinfoto check resolved IPsgetaddrinfoin thefinallyblockTesting
Before fix (Windows):
After fix (Windows):
Linux (unchanged):
Verified on: