Skip to content

Conversation

pappz
Copy link
Contributor

@pappz pappz commented Oct 1, 2025

Describe your changes

When an ICE agent connection was in progress, new offers were being ignored. This was incorrect logic because the remote agent could be restarted at any time.
In this change, whenever a new session ID is received, the ongoing handshake is closed and a new one is started.

  • Populate initial candidates in the ICE monitor.
  • Ensure the session ID is updated when the agent is recreated. Because of this, the Offer listener is now synchronized with the ICE listener.
  • Set the NB_ICE_MONITOR_PERIOD parameter to be configurable for end-to-end testing purposes

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)

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

Documentation

Select exactly one:

  • I added/updated documentation for this change
  • Documentation is not needed for this change (explain why)

Docs PR URL (required if "docs added" is checked)

Paste the PR link from https://github.com/netbirdio/docs here:

https://github.com/netbirdio/docs/pull/__

@Copilot Copilot AI review requested due to automatic review settings October 1, 2025 14:27
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 refactors the ICE agent connection logic to handle new session IDs more efficiently. The changes ensure that when a new session ID is received, the agent is properly recreated rather than being skipped.

  • Simplified connection state checking by combining agent existence and connection status checks
  • Moved session ID assignment to occur earlier in the connection process
  • Ensures session ID is set when creating the agent rather than after successful connection

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

if w.agent != nil {
if w.agent != nil || w.agentConnecting {
Copy link
Preview

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

The logic change from separate if w.agentConnecting and if w.agent != nil checks to a combined condition may alter the behavior. Previously, if agentConnecting was true, the function would return early without any session ID checks. Now it will proceed to check session IDs even when connecting. Ensure this behavioral change is intentional and doesn't introduce race conditions.

Suggested change
if w.agent != nil || w.agentConnecting {
if w.agentConnecting {
w.log.Debugf("agent is connecting, skipping the offer")
w.muxAgent.Unlock()
return
}
if w.agent != nil {

Copilot uses AI. Check for mistakes.

Comment on lines 134 to 136
if remoteOfferAnswer.SessionID != nil {
w.remoteSessionID = *remoteOfferAnswer.SessionID
}
Copy link
Preview

Copilot AI Oct 1, 2025

Choose a reason for hiding this comment

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

The session ID assignment has been moved from the connect method (which runs in a goroutine) to the main thread while holding the mutex. This is good for thread safety, but ensure that any code that depends on w.remoteSessionID being set after connection establishment still works correctly with this earlier assignment.

Copilot uses AI. Check for mistakes.

@pappz pappz changed the title Recreate agent when receive new session id [client] Recreate agent when receive new session id Oct 2, 2025
- Close depreacted agent before send offer answer
- Generate new session ID before send answer
@pappz pappz marked this pull request as ready for review October 5, 2025 09:58
w.muxAgent.Lock()
defer w.muxAgent.Unlock()

if w.agentConnecting {
Copy link
Member

Choose a reason for hiding this comment

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

could you explain why we create a new session if status is agent connection now?

Copy link

sonarqubecloud bot commented Oct 7, 2025

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