Fix: Add timeout to external IP address retrieval to prevent indefinite blocking#65
Open
mayank-quicksig wants to merge 1 commit intoangel-one:mainfrom
Open
Fix: Add timeout to external IP address retrieval to prevent indefinite blocking#65mayank-quicksig wants to merge 1 commit intoangel-one:mainfrom
mayank-quicksig wants to merge 1 commit intoangel-one:mainfrom
Conversation
nigilpaul
approved these changes
Sep 8, 2025
gulshan178
approved these changes
Nov 6, 2025
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
The
SmartConnectclass contains module-level code that executes on import, making HTTP requests toapi.ipify.orgwithout a timeout. This causes several critical issues:api.ipify.orgexperiences outages (which can last hours), theget()call blocks indefinitely waiting for a response__init__), it executes whenever the module is imported, even if the class is never instantiatedapi.ipify.orgoutages, regardless of whetherSmartConnectis actually usedRoot Cause
The
requests.get()call lacks atimeoutparameter, causing it to wait indefinitely for a response when the external service is unavailable.Solution
Add a 5-second timeout to the
get()request to ensure the import process completes within a reasonable timeframe, allowing dependent applications to continue functioning even when the external IP service is down.Changes
timeout=5parameter to therequests.get()callCode Changes
Testing
SmartConnectno longer hang indefinitely during service outagesBenefits
Risk Assessment
Low Risk: This is a defensive change that only affects error scenarios. Normal operation is unchanged, and the existing exception handling ensures graceful degradation when the timeout is reached.
Note: While this PR addresses the immediate blocking issue, consider refactoring the module-level execution in a future release to move IP retrieval into the class initialization or a lazy-loading pattern to further improve import performance and reliability.