mirror of
				https://github.com/zulip/zulip.git
				synced 2025-11-04 05:53:43 +00:00 
			
		
		
		
	outgoing_webhook: Set a default timeout of 10s.
Support for the timeouts, and tests for them, was added in53a8b2ac87-- though no code could have set them after31597cf33e. Add a 10-second default timeout. Observationally, p99 is just about 5s, with everything else being previously being destined to meet the 30s worker timeout; 10s provides a sizable buffer between them. Fixes #17742.
This commit is contained in:
		
				
					committed by
					
						
						Tim Abbott
					
				
			
			
				
	
			
			
			
						parent
						
							babe24fa02
						
					
				
				
					commit
					af26849554
				
			@@ -5,8 +5,10 @@ from time import perf_counter
 | 
			
		||||
from typing import Any, AnyStr, Dict, Optional
 | 
			
		||||
 | 
			
		||||
import requests
 | 
			
		||||
from django.conf import settings
 | 
			
		||||
from django.utils.translation import gettext as _
 | 
			
		||||
from requests import Response, Session
 | 
			
		||||
from urllib3 import HTTPResponse
 | 
			
		||||
 | 
			
		||||
from version import ZULIP_VERSION
 | 
			
		||||
from zerver.decorator import JsonableError
 | 
			
		||||
@@ -26,12 +28,26 @@ from zerver.models import (
 | 
			
		||||
)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class TimeoutAdapter(requests.adapters.HTTPAdapter):
 | 
			
		||||
    def __init__(self, timeout: Optional[int] = None, *args: Any, **kwargs: Any) -> None:
 | 
			
		||||
        self.timeout = timeout
 | 
			
		||||
        super().__init__(*args, *kwargs)
 | 
			
		||||
 | 
			
		||||
    def send(self, *args: Any, **kwargs: Any) -> HTTPResponse:
 | 
			
		||||
        if kwargs.get("timeout") is None:
 | 
			
		||||
            kwargs["timeout"] = self.timeout
 | 
			
		||||
        return super().send(*args, **kwargs)
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class OutgoingWebhookServiceInterface(metaclass=abc.ABCMeta):
 | 
			
		||||
    def __init__(self, token: str, user_profile: UserProfile, service_name: str) -> None:
 | 
			
		||||
        self.token: str = token
 | 
			
		||||
        self.user_profile: UserProfile = user_profile
 | 
			
		||||
        self.service_name: str = service_name
 | 
			
		||||
        self.session: Session = Session()
 | 
			
		||||
        timeout_adapter = TimeoutAdapter(timeout=settings.OUTGOING_WEBHOOK_TIMEOUT_SECONDS)
 | 
			
		||||
        self.session.mount("http://", timeout_adapter)
 | 
			
		||||
        self.session.mount("https://", timeout_adapter)
 | 
			
		||||
        self.session.headers.update(
 | 
			
		||||
            {
 | 
			
		||||
                "X-Smokescreen-Role": "webhook",
 | 
			
		||||
@@ -363,7 +379,9 @@ def do_rest_call(
 | 
			
		||||
            event["command"],
 | 
			
		||||
            event["service_name"],
 | 
			
		||||
        )
 | 
			
		||||
        failure_message = "A timeout occurred."
 | 
			
		||||
        failure_message = (
 | 
			
		||||
            f"Request timed out after {settings.OUTGOING_WEBHOOK_TIMEOUT_SECONDS} seconds."
 | 
			
		||||
        )
 | 
			
		||||
        request_retry(event, failure_message=failure_message)
 | 
			
		||||
        return None
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user