Skip to content

[client, android] Fix/notifier threading #3807

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
May 27, 2025
Merged

[client, android] Fix/notifier threading #3807

merged 8 commits into from
May 27, 2025

Conversation

pappz
Copy link
Contributor

@pappz pappz commented May 9, 2025

Describe your changes

  • Fix potential deadlocks
  • When adding a listener, immediately notify with the last known IP and fqdn.

Issue ticket number and link

Stack

Checklist

  • Is it a bug fix
  • Is a typo/documentation fix
  • Is a feature enhancement
  • It is a refactor
  • Created tests that fail without the change (if possible)
  • Extended the README / documentation, if necessary

@pappz pappz marked this pull request as ready for review May 27, 2025 08:08
@Copilot Copilot AI review requested due to automatic review settings May 27, 2025 08:08
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR removes the Android-specific stub router, unifies server routing on all platforms, and refactors the peer notifier to safely publish the last known address, FQDN, and peer count to new listeners while filtering out dynamic/domain routes in the routemanager notifier.

  • Drop server_android.go and lift !android build tag so the same server logic runs on Android
  • In notifier.go, filter out dynamic/domain routes when setting initial client routes
  • In peer/notifier.go, add last-known address/FQDN state, restructure locking, and immediately notify new listeners without deadlocking

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.

File Description
client/internal/routemanager/server_android.go Removed Android stub that returned “not supported” error
client/internal/routemanager/server.go Removed //go:build !android so server logic applies on Android
client/internal/routemanager/notifier/notifier.go Added filter to exclude dynamic/domain routes from initial client routes
client/internal/peer/notifier.go Tracked last address/FQDN, refactored locks, and extracted notify logic
Comments suppressed due to low confidence (2)

client/internal/peer/notifier.go:34

  • [nitpick] Variable name address is ambiguous. Rename to ipAddress for clarity and to distinguish from FQDN.
address := n.lastIPAddress

client/internal/routemanager/notifier/notifier.go:36

  • Filtering out dynamic/domain routes adds new behavior. Add unit tests covering both dynamic and static routes to verify they render in the initial list correctly.
if r.IsDynamic() {

Comment on lines +43 to +44
notifyListener(listener, lastNotification)
// run on go routine to avoid on Java layer to call go functions on same thread
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

State-change callbacks are now dispatched synchronously via notifyListener, which may block the caller or violate threading expectations on the Java side. Consider wrapping these calls in a goroutine, similar to OnPeersListChanged.

Suggested change
notifyListener(listener, lastNotification)
// run on go routine to avoid on Java layer to call go functions on same thread
// run on go routine to avoid on Java layer to call go functions on same thread
go notifyListener(listener, lastNotification)

Copilot uses AI. Check for mistakes.

Comment on lines 130 to +131
n.lastNumberOfPeers = numOfPeers
n.serverStateLock.Unlock()
Copy link
Preview

Copilot AI May 27, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The manual lock/unlock patterns repeat across methods, making the code verbose. Consider extracting a helper or using scoped defer blocks to simplify lock management.

Suggested change
n.lastNumberOfPeers = numOfPeers
n.serverStateLock.Unlock()
defer n.serverStateLock.Unlock()
n.lastNumberOfPeers = numOfPeers

Copilot uses AI. Check for mistakes.

Copy link

@pappz pappz merged commit 0492c17 into main May 27, 2025
32 checks passed
@pappz pappz deleted the fix/notifier-threading branch May 27, 2025 15:12
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