APP-240 Fix GitHub webhook timeout issue to prevent client disconnect errors (#11965)

Co-authored-by: openhands <openhands@all-hands.dev>
This commit is contained in:
Tim O'Farrell 2025-12-09 07:29:11 -07:00 committed by GitHub
parent 3743d10766
commit a9c76d0ed4
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -1,3 +1,4 @@
import asyncio
import hashlib
import hmac
import os
@ -58,7 +59,8 @@ async def github_events(
)
try:
payload = await request.body()
# Add timeout to prevent hanging on slow/stalled clients
payload = await asyncio.wait_for(request.body(), timeout=15.0)
verify_github_signature(payload, x_hub_signature_256)
payload_data = await request.json()
@ -78,6 +80,12 @@ async def github_events(
status_code=200,
content={'message': 'GitHub events endpoint reached successfully.'},
)
except asyncio.TimeoutError:
logger.warning('GitHub webhook request timed out waiting for request body')
return JSONResponse(
status_code=408,
content={'error': 'Request timeout - client took too long to send data.'},
)
except Exception as e:
logger.exception(f'Error processing GitHub event: {e}')
return JSONResponse(status_code=400, content={'error': 'Invalid payload.'})