Skip to contentSkip to conversation

Increase listen() backlog queue to 32

PATCH In review Gert Doering 3 participants 5 messages Aug 15, 2019 – Aug 16, 2019

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Increase listen() backlog queue to 32

For reasons historically unknown, OpenVPN sets the listen() backlog queue to "1", which signals the kernel "while there is one TCP connect waiting for OpenVPN to handle it, refuse all others" - which, on restarting a busy TCP server, will create connection issues.

The exact "best" value of the backlog queue is subject of discussion, but for a server that is not extremely busy with many connections coming in in parallel, there is no real difference between "10" or "500", as long as it's "more than 1".

Found and debugged by "mjo" in Trac.

Trac: #1208

---
 src/openvpn/socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/socket.c +1 -1
index c472cf1b..983ed38a 100644
@@ -1175,7 +1175,7 @@ socket_do_listen(socket_descriptor_t sd,
         ASSERT(local);
         msg(M_INFO, "Listening for incoming TCP connection on %s",
             print_sockaddr(local->ai_addr, &gc));
-        if (listen(sd, 1))
+        if (listen(sd, 32))
         {
             msg(M_ERR, "TCP: listen() failed");
         }
Signature · 1 line
2.21.0
Acked-by on v1 1/1
#1 lore raw

Hi,

Quoted 10 lines · Gert Doering

For reasons historically unknown, OpenVPN sets the listen() backlog queue to "1", which signals the kernel "while there is one TCP connect waiting for OpenVPN to handle it, refuse all others" - which, on restarting a busy TCP server, will create connection issues.

The exact "best" value of the backlog queue is subject of discussion, but for a server that is not extremely busy with many connections coming in in parallel, there is no real difference between "10" or "500", as long as it's "more than 1".

Quoted 5 lines

Found and debugged by "mjo" in Trac.

Trac: #1208

Having 1 is definitely unreasonable, and we need something larger. On top of that, mjo explained what kind of other side effects we can have when setting the queue to such a small value.

32 is reasonable and may even be worth a define so that it can be easily tweaked by whoever wants to. But this is another story..

Quoted 18 lines
---
 src/openvpn/socket.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
src/openvpn/socket.c +1 -1
index c472cf1b..983ed38a 100644
@@ -1175,7 +1175,7 @@ socket_do_listen(socket_descriptor_t sd,
         ASSERT(local);
         msg(M_INFO, "Listening for incoming TCP connection on %s",
             print_sockaddr(local->ai_addr, &gc));
-        if (listen(sd, 1))
+        if (listen(sd, 32))
         {
             msg(M_ERR, "TCP: listen() failed");
         }
Signature · 1 line
Antonio Quartulli
Acked-by on v1 1/1
#2 lore raw
In reply to Gert Doering
Quoted 10 lines · Gert Doering

For reasons historically unknown, OpenVPN sets the listen() backlog queue to "1", which signals the kernel "while there is one TCP connect waiting for OpenVPN to handle it, refuse all others" - which, on restarting a busy TCP server, will create connection issues.

The exact "best" value of the backlog queue is subject of discussion, but for a server that is not extremely busy with many connections coming in in parallel, there is no real difference between "10" or "500", as long as it's "more than 1".

Quoted 5 lines

Found and debugged by "mjo" in Trac.

Trac: #1208

I agree with Antonio, and we should make it somewhat easier to modify. I'm not sure if there's value in having it as a runtime option, like --socket-backlog (or something like that), or as a value you can pass to ./configure at compile time.

Signature · 4 lines
kind regards,

David Sommerseth
OpenVPN Inc
#3 lore raw

Hi,

Quoted 13 lines · David Sommerseth
Quoted 12 lines · Gert Doering

For reasons historically unknown, OpenVPN sets the listen() backlog queue to "1", which signals the kernel "while there is one TCP connect waiting for OpenVPN to handle it, refuse all others" - which, on restarting a busy TCP server, will create connection issues.

The exact "best" value of the backlog queue is subject of discussion, but for a server that is not extremely busy with many connections coming in in parallel, there is no real difference between "10" or "500", as long as it's "more than 1".

Found and debugged by "mjo" in Trac.

Quoted 7 lines
Quoted 3 lines

Trac: #1208

I agree with Antonio, and we should make it somewhat easier to modify.

I disagree with you on this point :D This is not something we expect people to play with. This is only a value that a developer with networking knowledge is expected to find and tweak. Hence my suggestion to make it a define in some header main header file.

Quoted 5 lines

I'm
not sure if there's value in having it as a runtime option, like --socket-backlog (or something like that), or as a value you can pass to ./configure at compile time.

Like above: yet another config option that the average joe can mess up and come up with unknown problems nobody will understand? nonono ;)

Cheers,

Quoted 8 lines

_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Signature · 1 line
Antonio Quartulli
#4 lore raw
In reply to Gert Doering

Wow, more ACKs than actual lines of codes affected .-) - I hear you wrt "have a #define somewhere" (and yes, we could do that) or "make it easier to configure for users" (nah... for the reasons Antonio gave) :-)

Patch has been applied to the master and release/2.4 branch.

2.4, because (see the discussion in the ticket) this effectively acknowledges the changing nature of the internet, with ubiquitous background scanning on well-known ports like TCP/443 - thus getting in the way of production openvpn setups with "listen(s,1)".

commit 6d8380c78bf77766454b93b49ab2ebf713b0be48 (master) commit ec0ca68f4ed1e6aa6f08f470b18e0198b7e5a4da (release/2.4)

Author: Gert Doering
Date:   Thu Aug 15 17:53:19 2019 +0200
     Increase listen() backlog queue to 32

     Signed-off-by: Gert Doering <[email protected]...>
     Acked-by: Antonio Quartulli <[email protected]...>
     Acked-by: David Sommerseth <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg18758.html
     Signed-off-by: Gert Doering <[email protected]...>

--
kind regards,

Gert Doering