proxy: fix resource leaks and improve mobile battery life#861
Open
cyrilleberaud wants to merge 2 commits into
Open
proxy: fix resource leaks and improve mobile battery life#861cyrilleberaud wants to merge 2 commits into
cyrilleberaud wants to merge 2 commits into
Conversation
Server: Reduce HTTP idle connection timeout from ~24 days (numeric_limits<int>::max() milliseconds) to 1 hour. Dead mobile clients are now cleaned up promptly instead of holding server resources for weeks. Client: Add exponential backoff for proxy reconnection when disconnected (1 min -> 2 -> 4 -> 8 -> 16 -> 30 min cap). Previously used a fixed 1-minute retry which drained battery on flaky mobile networks. Reset backoff on successful connection or explicit connectivity change (WiFi/cellular switch). Client: Add small random jitter (0-2s) before resubscribing all listeners on reconnection to avoid burst of requests to the server. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> Change-Id: Ic29c4a0b2850997db9e559f01146024f41190a5c
The HTTP Urgency header set on WebPush requests is not exposed to
UnifiedPush Android clients by the connector library. Include a
"priority" field ("high" or "normal") directly in the JSON body
so that clients can determine whether a push notification requires
immediate wake-up processing or can be deferred until the next
natural activity.
This complements the daemon-side priority assignment (Gerrit #34059)
and allows UnifiedPush (F-Droid) builds to benefit from the same
battery savings as FCM builds.
Change-Id: Id316ff89e64e59d1b224f5b4e14da6b36dc62c95
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR targets excessive proxy resource usage and mobile battery drain by tightening server-side HTTP timeouts and making client reconnection/listener restarts less aggressive.
Changes:
- Server: reduce RESTinio idle/read request time limits from ~24 days to 1 hour; add push
priorityinto UnifiedPush JSON payload. - Client: introduce exponential backoff for proxy confirmation/reconnect attempts (1 → 2 → 4 → … → 30 minutes) and add a small reconnect-time jitter before restarting listeners.
- Repo hygiene: ignore
jamid.log.
Reviewed changes
Copilot reviewed 3 out of 4 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
src/dht_proxy_server.cpp |
Uses a bounded (1h) connection/message timeout; adds push priority to UnifiedPush JSON payload. |
src/dht_proxy_client.cpp |
Adds reconnect backoff logic and a reconnect-time jitter before restarting listeners. |
include/opendht/dht_proxy_client.h |
Stores backoff state (proxyRetryDelay_) and a max cap constant. |
.gitignore |
Ignores jamid.log. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+1179
to
+1180
| // Reset backoff on explicit connectivity change (e.g., WiFi/cellular switch) | ||
| proxyRetryDelay_ = std::chrono::minutes(1); |
Comment on lines
+785
to
+788
| // Small random delay (0-2s) to avoid resubscription burst | ||
| auto jitter = std::chrono::milliseconds( | ||
| std::rand() % 2000); | ||
| listenerRestartTimer_->expires_at(std::chrono::steady_clock::now() + jitter); |
Comment on lines
+785
to
790
| // Small random delay (0-2s) to avoid resubscription burst | ||
| auto jitter = std::chrono::milliseconds( | ||
| std::rand() % 2000); | ||
| listenerRestartTimer_->expires_at(std::chrono::steady_clock::now() + jitter); | ||
| listenerRestartTimer_->async_wait(std::bind(&DhtProxyClient::restartListeners, this, std::placeholders::_1)); | ||
| if (not onConnectCallbacks_.empty()) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fix three proxy issues that cause excessive resource usage on the server and battery drain on mobile clients.
Server: Fix HTTP connection timeout
read_next_http_message_timelimitwas set tostd::numeric_limits<int>::max()milliseconds (~24 days)Client: Add exponential backoff for reconnection
getConnectivityStatus())Client: Add jitter to listener resubscription
These fixes are part of a broader effort to make Jami work reliably with push notifications on Android while minimizing battery usage.