Connected field is true after netbird down #960

Open
opened 2025-11-20 05:20:38 -05:00 by saavagebueno · 4 comments
Owner

Originally created by @ctrl-zzz on GitHub (Jun 8, 2024).

Describe the problem

I've been trying to implement a session-expire feature that checks the connected status of a peer; when a peer gets disconnected its login is marked as expired.
The problem is that after netbird down the connected status seems to be stuck at true, so the session can never expire.

I've made sure my code doesn't interfere with the expected behavior and double checked without applying my changes that the problem persists.

To Reproduce

Steps to reproduce the behavior:

  1. In the management/server/account.go file print the peer.Status.Connected value immediately after the MarkPeerConnected call
  2. Deploy code
  3. Get NetBird started
  4. Perform netbird up and netbird down
  5. Check printed value of the connected field

Expected behavior

The connected field should be set to false.

Are you using NetBird Cloud?

No, I'm selfhosting it.

Additional context

When GETting a peer using the NetBird REST API its connected field behaves normally, being set at false after netbird down.

Originally created by @ctrl-zzz on GitHub (Jun 8, 2024). **Describe the problem** I've been trying to implement a session-expire feature that checks the `connected` status of a peer; when a peer gets disconnected its login is marked as expired. The problem is that after `netbird down` the `connected` status seems to be stuck at `true`, so the session can never expire. I've made sure my code doesn't interfere with the expected behavior and double checked without applying my changes that the problem persists. **To Reproduce** Steps to reproduce the behavior: 1. In the `management/server/account.go` file print the `peer.Status.Connected` value immediately after the [MarkPeerConnected call](https://github.com/netbirdio/netbird/blob/main/management/server/account.go#L1897C53-L1897C59) 2. Deploy code 3. Get NetBird started 4. Perform `netbird up` and `netbird down` 5. Check printed value of the `connected` field **Expected behavior** The `connected` field should be set to false. **Are you using NetBird Cloud?** No, I'm selfhosting it. **Additional context** When GETting a peer using the NetBird REST API its `connected` field behaves normally, being set at `false` after `netbird down`.
saavagebueno added the bugpeer-managementmanagement-service labels 2025-11-20 05:20:38 -05:00
Author
Owner

@ctrl-zzz commented on GitHub (Jun 12, 2024):

Hello,

I've been looking for the issue and I noticed that the connected field is also set to true in the db, even after a disconnection. There's not a problem while retrieving the value, it just never gets updated after a netbird down.

The problem should be in how the field gets updated in the SavePeerStatus function in the management/server/sql_store.go file, particularly because of how GORM manages the update itself. There's an explanation on the GORM documentation on why this happens; updating the SavePeerStatus function accordingly solved the problem for me. Now the status field gets updated correctly and its value in the db stays consistent.

This could be an issue for other updates as well, so I wanted to give you a heads up about it.

@ctrl-zzz commented on GitHub (Jun 12, 2024): Hello, I've been looking for the issue and I noticed that the `connected` field is also set to `true` in the db, even after a disconnection. There's not a problem while retrieving the value, it just never gets updated after a `netbird down`. The problem should be in how the field gets updated in the [SavePeerStatus function](https://github.com/netbirdio/netbird/blob/94e505480b19ac31a27a4c9fb2d677671aab1428/management/server/sql_store.go#L242) in the `management/server/sql_store.go` file, particularly because of how GORM manages the update itself. There's an [explanation on the GORM documentation](https://gorm.io/docs/update.html#Updates-multiple-columns) on why this happens; updating the `SavePeerStatus` function accordingly solved the problem for me. Now the `status` field gets updated correctly and its value in the db stays consistent. This could be an issue for other updates as well, so I wanted to give you a heads up about it.
Author
Owner

@nazarewk commented on GitHub (Apr 23, 2025):

@ctrl-zzz @bcmmbaga Any idea whether this still happens with the latest NetBird version? There seems to be a merged PR referencing this issue

@nazarewk commented on GitHub (Apr 23, 2025): @ctrl-zzz @bcmmbaga Any idea whether this still happens with the latest NetBird version? There seems to be a merged PR referencing this issue
Author
Owner

@ctrl-zzz commented on GitHub (Apr 23, 2025):

@ctrl-zzz @bcmmbaga Any idea whether this still happens with the latest NetBird version? There seems to be a merged PR referencing this issue

I implemented a fix that resolved this issue, and it was merged with my PR. At the time, the problem no longer occurred - at least up until the last time I tested it. However, I'm not sure if the issue may have resurfaced with more recent versions :)

@ctrl-zzz commented on GitHub (Apr 23, 2025): > @ctrl-zzz @bcmmbaga Any idea whether this still happens with the latest NetBird version? There seems to be a merged PR referencing this issue I implemented a fix that resolved this issue, and it was merged with my PR. At the time, the problem no longer occurred - at least up until the last time I tested it. However, I'm not sure if the issue may have resurfaced with more recent versions :)
Author
Owner

@bcmmbaga commented on GitHub (Apr 23, 2025):

@ctrl-zzz @bcmmbaga Any idea whether this still happens with the latest NetBird version? There seems to be a merged PR referencing this issue

The fix has been merged and this is no longer an issue with the latest version

@bcmmbaga commented on GitHub (Apr 23, 2025): > [@ctrl-zzz](https://github.com/ctrl-zzz) [@bcmmbaga](https://github.com/bcmmbaga) Any idea whether this still happens with the latest NetBird version? There seems to be a merged PR referencing this issue The fix has been merged and this is no longer an issue with the latest version
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SVI/netbird#960