Skip to content

Conversation

@rmaher001
Copy link
Contributor

Why

The event stream disconnects every 5 minutes, causing the integration to miss important IVS events during reconnection.

What

  • Set ClientTimeout(total=None) on the event stream request to disable aiohttp's default 300-second timeout
  • Allows the event stream to run indefinitely as intended
  • Tested for 24+ hours without disconnections

The Dahua integration was setting heartbeat=5 in the event subscription URL
but never actually sending keepalive messages, causing the connection to
timeout after ~300 seconds (5 minutes).

This fix:
- Creates an async task that sends keepalive requests every 5 seconds
- Uses a lightweight API endpoint for keepalive messages
- Properly cleans up the keepalive task when the connection closes
- Prevents the camera from timing out the event stream

Tested with actual Dahua camera - connection remains stable beyond 5 minutes.
…connections

The Dahua event stream was disconnecting every 5 minutes due to aiohttp's
default total timeout of 300 seconds. Since the event stream is meant to
run indefinitely, this timeout should be disabled.

This fix adds ClientTimeout(total=None) to the event stream request,
allowing it to maintain persistent connection for IVS events monitoring.

Tested for 50+ minutes with no disconnections.

Fixes issue where important IVS events could be missed during reconnection.
@rroller rroller merged commit 602a85f into rroller:main Oct 3, 2025
@rroller
Copy link
Owner

rroller commented Oct 3, 2025

Thank you!

rmaher001 added a commit to rmaher001/dahua that referenced this pull request Oct 5, 2025
The previous fix (rroller#501) applied the timeout at the request level in client.py.
This applies the same fix at the session level in __init__.py, which is more
appropriate as the session is created specifically for the Dahua client.

- Set timeout=ClientTimeout(total=None) on ClientSession creation
- Validated in production with no timeouts
rmaher001 added a commit to rmaher001/dahua that referenced this pull request Oct 5, 2025
Moves timeout fix from request level (rroller#501) to session level, which is more appropriate since the session is created specifically for the Dahua client.

Changes:
- Add timeout=ClientTimeout(total=None) to ClientSession creation in __init__.py
- Revert request-level timeout fix from client.py

The session-level fix prevents the default 5-minute timeout from disconnecting infinite event streams while keeping regular API requests properly scoped.

Tested in production with no timeout errors.
@rmaher001
Copy link
Contributor Author

rmaher001 commented Oct 5, 2025 via email

rroller pushed a commit that referenced this pull request Oct 6, 2025
Moves timeout fix from request level (#501) to session level, which is more appropriate since the session is created specifically for the Dahua client.

Changes:
- Add timeout=ClientTimeout(total=None) to ClientSession creation in __init__.py
- Revert request-level timeout fix from client.py

The session-level fix prevents the default 5-minute timeout from disconnecting infinite event streams while keeping regular API requests properly scoped.

Tested in production with no timeout errors.
rroller added a commit that referenced this pull request Oct 10, 2025
@rroller
Copy link
Owner

rroller commented Oct 10, 2025

Had to revert this, users are reporting issues

@rmaher001
Copy link
Contributor Author

rmaher001 commented Oct 12, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants