{"record":{"id":"e7dc67e2e5c0222f","repo":"apache/beam","slug":"timeout-timeout-exceeded-while-completing-request-request","errorCode":null,"errorMessage":"Timeout {timeout} exceeded while completing request: {request}","messagePattern":"Timeout (.+?) exceeded while completing request: (.+?)","errorType":"exception","errorClass":"UserCodeTimeoutException","httpStatus":null,"severity":"error","filePath":"sdks/python/apache_beam/io/requestresponse.py","lineNumber":205,"sourceCode":"\ndef _execute_request(\n    caller: Caller[RequestT, ResponseT],\n    request: RequestT,\n    timeout: float,\n    metrics_collector: Optional[_MetricsCollector] = None) -> ResponseT:\n  with concurrent.futures.ThreadPoolExecutor() as executor:\n    future = executor.submit(caller, request)\n    try:\n      return future.result(timeout=timeout)\n    except TooManyRequests as e:\n      _LOGGER.info(\n          'request could not be completed. got code %i from the service.',\n          e.code)\n      raise e\n    except concurrent.futures.TimeoutError:\n      if metrics_collector:\n        metrics_collector.timeout_requests.inc(1)\n      raise UserCodeTimeoutException(\n          f'Timeout {timeout} exceeded '\n          f'while completing request: {request}')\n    except RuntimeError:\n      if metrics_collector:\n        metrics_collector.failures.inc(1)\n      raise UserCodeExecutionException('could not complete request')\n\n\nclass ExponentialBackOffRepeater(Repeater):\n  \"\"\"Configure exponential backoff retry strategy.\n\n  It retries for exceptions due to the remote service such as\n  TooManyRequests (HTTP 429), UserCodeTimeoutException, UserCodeQuotaException.\n\n  It utilizes the decorator\n  :func:`apache_beam.utils.retry.with_exponential_backoff`.\n  \"\"\"\n  def __init__(self):","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/python/apache_beam/io/requestresponse.py#L187-L223","documentation":"RequestResponseIO's _execute_request raises UserCodeTimeoutException when the user call completes via a future that hits the configured timeout (concurrent.futures.TimeoutError). The timeout metric is incremented and the original request is included in the message.","triggerScenarios":"Calling RequestResponseIO with a CallTimeoutExceededException-configured timeout where the user's callable or the remote service takes longer than `timeout` seconds; slow or hanging HTTP calls to the remote API.","commonSituations":"Remote service latency spikes; user-supplied callable doing blocking I/O without its own timeout; timeout configured too low for normal request duration.","solutions":["Increase the timeout via a custom Repeater / timeout parameter passed to RequestResponseIO.","Add an internal timeout and fast-fail behavior in the user callable so it returns an error instead of hanging.","Verify the remote service health/latency; add retry with exponential backoff (ExponentialBackOffRepeater) for transient slowness.","Optimize or batch the request if it is inherently slow."],"exampleFix":"// before\nRequestResponseIO(caller, timeout=2)\n// after\nRequestResponseIO(caller, timeout=30, repeater=ExponentialBackOffRepeater(retries=3))","handlingStrategy":"retry","validationCode":"import time\ndef within_timeout(last_duration, timeout):\n  return last_duration is None or last_duration < timeout","typeGuard":null,"tryCatchPattern":"try:\n  result = do_request(request)\nexcept UserCodeTimeoutException as e:\n  logging.warning('request timed out: %s', e)\n  # retry with backoff or fail the element","preventionTips":["Set realistic timeouts based on measured service latency","Add timeouts inside the user callable itself","Use ExponentialBackOffRepeater for transient slowness","Monitor the timeout_requests metric"],"tags":["python","apache-beam","timeout","http"],"backgroundTag":"request-timeout","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}