-
Notifications
You must be signed in to change notification settings - Fork 151
handle-invalid-gateway-url #600
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Signed-off-by: Satya <[email protected]>
…alid gateway URL's Signed-off-by: Satya <[email protected]>
ac8dffd
to
15c0303
Compare
The PR successfully adds gateway connection validation with a new Implementation Recommendations1. Make Validation Timeout ConfigurableAdd to # Gateway validation settings
gateway_validation_timeout: int = 5 # seconds Add to # Timeout for gateway validation requests (seconds)
GATEWAY_VALIDATION_TIMEOUT=5 Update async def _validate_gateway_url(self, url: str, headers: dict, transport_type: str, timeout=None):
"""
Validate if the given URL is a live Server-Sent Events (SSE) endpoint.
Args:
url (str): The full URL of the endpoint to validate.
headers (dict): Headers to be included in the requests (e.g., Authorization).
transport_type (str): SSE or STREAMABLEHTTP
timeout (int, optional): Timeout in seconds. Defaults to settings.gateway_validation_timeout.
Returns:
bool: True if the endpoint is reachable and supports SSE/StreamableHTTP, otherwise False.
"""
if timeout is None:
timeout = settings.gateway_validation_timeout
async with httpx.AsyncClient(verify=not settings.skip_ssl_verify) as client:
timeout_obj = httpx.Timeout(timeout)
# ... rest of implementation 2. Use Existing SSL Verification SettingThe current implementation should already use async with httpx.AsyncClient(verify=not settings.skip_ssl_verify) as client: 3. Add Debug Logging for Error DetailsTo maintain simple user-facing errors while preserving debugging information, update exception handling: # In _validate_gateway_url
except Exception as e:
logger.debug(f"Gateway validation failed for {url}: {str(e)}", exc_info=True)
return False
# In _initialize_gateway
except Exception as e:
logger.debug(f"Gateway initialization failed for {url}: {str(e)}", exc_info=True)
raise GatewayConnectionError(f"Failed to initialize gateway at {url}") 4. Consider Retry StrategyFor consistency with other HTTP operations in the codebase, consider using # Alternative implementation using ResilientHttpClient
validation_client = ResilientHttpClient(
client_args={
"timeout": settings.gateway_validation_timeout,
"verify": not settings.skip_ssl_verify
}
)
try:
async with validation_client.stream("GET", url, headers=headers) as response:
# ... validation logic
finally:
await validation_client.aclose() 5. Handle Edge CasesConsider adding specific handling for common failure scenarios:
Testing RecommendationsAdd test coverage for:
Performance Considerations
Final NotesThese changes maintain backward compatibility while adding necessary configuration flexibility. The validation timeout defaults to 5 seconds but can be tuned based on network conditions. SSL verification respects the existing global setting, avoiding the need for a separate configuration option. |
🐛 Bug-fix for PR 476
📌 Summary
💡 Fix Description
🧪 Verification
make test
make black
make lint-web
📐 MCP Compliance (if relevant)
✅ Checklist
make black isort pre-commit
)Example for testing invalid gateway servers
All of the above will be handled in the 'validate_gateway_url', exception will be raised if they are invalid or not reachable
Signed-off-by: Satya [email protected]