Seeing sysctl errors when adding a lot of routes #686

Closed
opened 2025-11-20 05:15:58 -05:00 by saavagebueno · 10 comments
Owner

Originally created by @hurricanehrndz on GitHub (Mar 8, 2024).

Describe the problem

A clear and concise description of what the problem is.

2024-03-08T14:53:05-07:00 ERRO client/internal/routemanager/client.go:276: route {subnet} couldn't be added for peer 100.122.204.13, err: sysctl: cannot allocate memory

To Reproduce
Add many routes to a routing

Steps to reproduce the behavior:

  1. Advertise and extensive amount of routes
  2. Connect
  3. Grep for sysctl lines
  4. See error

Expected behavior

I am assuming errors with allocating memory is not good

A clear and concise description of what you expected to happen.

Are you using NetBird Cloud?
No, self hosted

NetBird version
0.26.2
netbird version

NetBird status -d output:

Originally created by @hurricanehrndz on GitHub (Mar 8, 2024). **Describe the problem** A clear and concise description of what the problem is. ```sh 2024-03-08T14:53:05-07:00 ERRO client/internal/routemanager/client.go:276: route {subnet} couldn't be added for peer 100.122.204.13, err: sysctl: cannot allocate memory ``` **To Reproduce** Add many routes to a routing Steps to reproduce the behavior: 1. Advertise and extensive amount of routes 2. Connect 3. Grep for sysctl lines 4. See error **Expected behavior** I am assuming errors with allocating memory is not good A clear and concise description of what you expected to happen. **Are you using NetBird Cloud?** No, self hosted **NetBird version** 0.26.2 `netbird version` **NetBird status -d output:**
saavagebueno added the bugclientroutesmacos labels 2025-11-20 05:15:58 -05:00
Author
Owner

@mlsmaycon commented on GitHub (Mar 8, 2024):

@hurricanehrndz can you share how many routes, the OS and how much memory you have in the system?

@mlsmaycon commented on GitHub (Mar 8, 2024): @hurricanehrndz can you share how many routes, the OS and how much memory you have in the system?
Author
Owner

@hurricanehrndz commented on GitHub (Mar 9, 2024):

@mlsmaycon this has nothing to do with memory, but how BSD systems operate. As I understand it the routing tables get expanded as routes are added. At times when said routing tables are being expanded the commands will fail as describe above.

I am on a macos device, I have implemented a less than elegant solution. It does work though.

From d660cad7d066078441a58dfb65d0f28b68c0995f Mon Sep 17 00:00:00 2001
From: Carlos Hernandez <carlos@hrndz.ca>
Date: Fri, 8 Mar 2024 15:46:00 -0700
Subject: [PATCH] Hail-mary for route issues

---
 client/internal/routemanager/client.go | 9 ++++++++-
 1 file changed, 8 insertions(+), 1 deletion(-)

diff --git a/client/internal/routemanager/client.go b/client/internal/routemanager/client.go
index ee98d50..dd812f8 100644
--- a/client/internal/routemanager/client.go
+++ b/client/internal/routemanager/client.go
@@ -271,7 +271,14 @@ func (c *clientNetwork) peersStateAndUpdateWatcher() {
 			}
 			return
 		case <-c.peerStateUpdate:
-			err := c.recalculateRouteAndUpdatePeerAndSystem()
+			var err error
+			for i := 1; i <=5; i++ {
+				err = c.recalculateRouteAndUpdatePeerAndSystem()
+				if err == nil {
+					break
+				}
+				log.Error("Re-Attempting to recalculateRouteAndUpdatePeerAndSystem")
+			}
 			if err != nil {
 				log.Error(err)
 			}
@hurricanehrndz commented on GitHub (Mar 9, 2024): @mlsmaycon this has nothing to do with memory, but how BSD systems operate. As I understand it the routing tables get expanded as routes are added. At times when said routing tables are being expanded the commands will fail as describe above. I am on a macos device, I have implemented a less than elegant solution. It does work though. ``` From d660cad7d066078441a58dfb65d0f28b68c0995f Mon Sep 17 00:00:00 2001 From: Carlos Hernandez <carlos@hrndz.ca> Date: Fri, 8 Mar 2024 15:46:00 -0700 Subject: [PATCH] Hail-mary for route issues --- client/internal/routemanager/client.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/client/internal/routemanager/client.go b/client/internal/routemanager/client.go index ee98d50..dd812f8 100644 --- a/client/internal/routemanager/client.go +++ b/client/internal/routemanager/client.go @@ -271,7 +271,14 @@ func (c *clientNetwork) peersStateAndUpdateWatcher() { } return case <-c.peerStateUpdate: - err := c.recalculateRouteAndUpdatePeerAndSystem() + var err error + for i := 1; i <=5; i++ { + err = c.recalculateRouteAndUpdatePeerAndSystem() + if err == nil { + break + } + log.Error("Re-Attempting to recalculateRouteAndUpdatePeerAndSystem") + } if err != nil { log.Error(err) } ```
Author
Owner

@hurricanehrndz commented on GitHub (Mar 9, 2024):

You can find more info on the issue here:
https://lists.freebsd.org/pipermail/freebsd-current/2014-February/048416.html

@hurricanehrndz commented on GitHub (Mar 9, 2024): You can find more info on the issue here: https://lists.freebsd.org/pipermail/freebsd-current/2014-February/048416.html
Author
Owner

@hurricanehrndz commented on GitHub (Mar 12, 2024):

@mlsmaycon did you want a PR?

@hurricanehrndz commented on GitHub (Mar 12, 2024): @mlsmaycon did you want a PR?
Author
Owner

@mlsmaycon commented on GitHub (Mar 12, 2024):

@hurricanehrndz I would like to validate it a bit more on our end.

Can you share the number of routes it was added to when you faced the issue?

@mlsmaycon commented on GitHub (Mar 12, 2024): @hurricanehrndz I would like to validate it a bit more on our end. Can you share the number of routes it was added to when you faced the issue?
Author
Owner

@hurricanehrndz commented on GitHub (Mar 12, 2024):

Let me see if I can get you a santized version of it

@hurricanehrndz commented on GitHub (Mar 12, 2024): Let me see if I can get you a santized version of it
Author
Owner

@hurricanehrndz commented on GitHub (Mar 12, 2024):

112 routes

@hurricanehrndz commented on GitHub (Mar 12, 2024): 112 routes
Author
Owner

@mlsmaycon commented on GitHub (Mar 12, 2024):

Got it, thanks

@mlsmaycon commented on GitHub (Mar 12, 2024): Got it, thanks
Author
Owner

@hurricanehrndz commented on GitHub (Mar 27, 2024):

Any further thoughts whether I should submit a PR for this?

@hurricanehrndz commented on GitHub (Mar 27, 2024): Any further thoughts whether I should submit a PR for this?
Author
Owner

@lixmal commented on GitHub (Mar 27, 2024):

Hi @hurricanehrndz, I haven't been able to reproduce the issue so far, but from my research a single retry should suffice if this appears. Thanks for your patch, however I would like to issue the retry closer to the macos system command.

@lixmal commented on GitHub (Mar 27, 2024): Hi @hurricanehrndz, I haven't been able to reproduce the issue so far, but from my research a single retry should suffice if this appears. Thanks for your patch, however I would like to issue the retry closer to the macos system command.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: SVI/netbird#686