-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[management] fix skip of ephemeral peers on deletion #5206
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -108,10 +108,19 @@ func (m *managerImpl) DeletePeers(ctx context.Context, accountID string, peerIDs | |
| err = m.store.ExecuteInTransaction(ctx, func(transaction store.Store) error { | ||
| peer, err := transaction.GetPeerByID(ctx, store.LockingStrengthNone, accountID, peerID) | ||
| if err != nil { | ||
| if e, ok := status.FromError(err); ok && e.Type() == status.NotFound { | ||
| log.WithContext(ctx).Tracef("DeletePeers: peer %s not found, skipping", peerID) | ||
| return nil | ||
| } | ||
| return err | ||
| } | ||
|
|
||
| if checkConnected && (peer.Status.Connected || peer.Status.LastSeen.After(time.Now().Add(-(ephemeral.EphemeralLifeTime - 10*time.Second)))) { | ||
| log.WithContext(ctx).Tracef("DeletePeers: peer %s skipped (connected=%t, lastSeen=%s, threshold=%s, ephemeral=%t)", | ||
| peerID, peer.Status.Connected, | ||
| peer.Status.LastSeen.Format(time.RFC3339), | ||
| time.Now().Add(-(ephemeral.EphemeralLifeTime - 10*time.Second)).Format(time.RFC3339), | ||
| peer.Ephemeral) | ||
| return nil | ||
| } | ||
|
|
||
|
|
@@ -150,7 +159,8 @@ func (m *managerImpl) DeletePeers(ctx context.Context, accountID string, peerIDs | |
| return nil | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| log.WithContext(ctx).Errorf("DeletePeers: failed to delete peer %s: %v", peerID, err) | ||
| continue | ||
| } | ||
|
Comment on lines
161
to
164
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: # First, let's examine the file structure and find the DeletePeers function
cd management/internals/modules/peers
wc -l manager.goRepository: netbirdio/netbird Length of output: 75 🏁 Script executed: # Read the DeletePeers function - lines around 161-179 to see full context
sed -n '140,185p' management/internals/modules/peers/manager.goRepository: netbirdio/netbird Length of output: 1304 🏁 Script executed: # Search for all callers of DeletePeers function
rg -n 'DeletePeers\s*\(' --type=go -g '!*_mock.go' -g '!*_test.go'Repository: netbirdio/netbird Length of output: 568 🏁 Script executed: # Read the caller context in ephemeral manager
sed -n '180,210p' management/internals/modules/peers/ephemeral/manager/ephemeral.goRepository: netbirdio/netbird Length of output: 891 🏁 Script executed: # Search for tests of DeletePeers to understand intended behavior
rg -n 'DeletePeers' --type=go -A 10 -B 2 | grep -E '(test|Test|_test\.go)' -A 10 -B 2Repository: netbirdio/netbird Length of output: 6933 🏁 Script executed: # Look for all test files that test DeletePeers
find . -name '*_test.go' -type f -exec grep -l 'DeletePeers' {} \;Repository: netbirdio/netbird Length of output: 133 🏁 Script executed: # Read the DeletePeers function signature and any comments
sed -n '99,110p' management/internals/modules/peers/manager.goRepository: netbirdio/netbird Length of output: 630 🏁 Script executed: # Also check if there's an interface definition that documents expected behavior
rg -n 'interface Manager' -A 20 management/internals/modules/peers/manager.goRepository: netbirdio/netbird Length of output: 43 🏁 Script executed: # Check the interface definition for DeletePeers
rg -n 'DeletePeers' management/internals/modules/peers/manager.go | head -5Repository: netbirdio/netbird Length of output: 619 🏁 Script executed: # Look for the interface definition in the same file
sed -n '1,50p' management/internals/modules/peers/manager.goRepository: netbirdio/netbird Length of output: 2218 The error-on-continue behavior is intentional for ephemeral cleanup, but clarify the misleading error contract. The function's design—logging errors and continuing to the next peer without failing—is appropriate for ephemeral peer cleanup (temporary peers will expire anyway). However, the function signature declares an Consider documenting this as best-effort cleanup, or distinguish between ephemeral cleanup (which can be best-effort) and other deletion scenarios that may require stricter error handling. Alternatively, return an error summary or retry count to make the contract explicit. 🤖 Prompt for AI Agents |
||
|
|
||
| if m.integratedPeerValidator != nil { | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.