Skip to content

[client] Fix race issues in lazy tests #4181

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

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

pappz
Copy link
Contributor

@pappz pappz commented Jul 20, 2025

Describe your changes

Fix race issues in lazy tests

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

By submitting this pull request, you confirm that you have read and agree to the terms of the Contributor License Agreement.

@Copilot Copilot AI review requested due to automatic review settings July 20, 2025 23:10
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 fixes race conditions in lazy connection tests by adding proper synchronization when accessing peer listeners. The changes introduce a thread-safe method to retrieve peer listeners and update test code to use this method instead of directly accessing the internal peers map.

  • Adds a GetPeerListener method with proper mutex locking for thread-safe access
  • Updates test functions to use the new safe accessor method instead of direct map access
  • Improves error handling by checking for peer listener existence before use

if err := trigger(mgr.peers[peerCfg2.PeerConnID].conn.LocalAddr().String()); err != nil {
listener, exists = mgr.GetPeerListener(peerCfg2.PeerConnID)
if !exists {
t.Fatalf("peer listener for peer1 not found")
Copy link
Preview

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

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

The error message incorrectly refers to 'peer1' but should refer to 'peer2' since this is checking for peerCfg2.PeerConnID.

Suggested change
t.Fatalf("peer listener for peer1 not found")
t.Fatalf("peer listener for peer2 not found")

Copilot uses AI. Check for mistakes.

@@ -33,6 +33,15 @@ func (m MocWGIface) UpdatePeer(string, []netip.Prefix, time.Duration, *net.UDPAd

}

// Add this method to the Manager struct
Copy link
Preview

Copilot AI Jul 20, 2025

Choose a reason for hiding this comment

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

This comment suggests adding the method to the Manager struct, but the method is actually being added to the test file. The comment should clarify that this is a test helper method or be moved to the actual Manager struct implementation.

Copilot uses AI. Check for mistakes.

Copy link

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.

1 participant