fix: add request timeouts to multimodal URL fetches - #2507
Closed
bunlongheng wants to merge 1 commit into
Closed
Conversation
Several requests.get/head calls that download image, audio, and PDF content from remote URLs did not pass a timeout, so a slow or unresponsive host could hang the calling thread indefinitely (uncontrolled resource consumption, CWE-400). The GCS helpers in the same module already use a 30s timeout; this applies the same default to the remaining fetches and adds regression tests asserting a timeout is passed.
Collaborator
|
Consolidated and merged in #2510. The original timeout changes and authorship were preserved; the consolidation also repaired four stale request mocks, asserted all changed timeout paths, and passed the full CI/release matrix. |
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
Several
requests.get/requests.headcalls in the multimodal helpers download image, audio, and PDF content from remote URLs without passing a timeout. Because Python'srequestshas no default timeout, a slow or unresponsive host can hang the calling thread indefinitely (uncontrolled resource consumption, CWE-400). This is a denial-of-service hardening gap: a single unreachable media URL can stall a request pipeline forever.The GCS helpers in the same module (
from_gs_url) already use a 30s timeout, andbedrock/handlers.pyusestimeout=30too, so the codebase already treats 30s as the convention. This PR simply extends that same default to the remaining fetches.Fixed call sites
instructor/v2/core/multimodal.py-Image.from_url(HEAD probe),Image.url_to_base64,Audio.from_url,PDF.from_url(HEAD probe)instructor/v2/providers/anthropic/multimodal.py-pdf_to_anthropicinstructor/v2/providers/genai/multimodal.py-image_to_genai,pdf_to_genaiinstructor/v2/providers/openai/multimodal.py-pdf_to_openaiChange
Each remote fetch now passes
timeout=30, matching the existing convention. No behavior change for healthy hosts; unresponsive hosts now fail fast instead of hanging.Tests
Added two regression tests in
tests/multimodal/test_multimodal.pyasserting a timeout is passed on both therequests.getandrequests.headpaths. Full multimodal suite passes: 62 passed, 1 skipped.