Getting error: Invalid argument after setting "net.core.somaxconn" value greater than 65535 in RHEL 7?
Environment
- Red Hat Enterprise Linux(RHEL) 7
Issue
- Why does RHEL 7 get an error: "Invalid argument" after setting
net.core.somaxconn
value greater than 65535 while RHEL 6 don't?
Resolution
The sk_max_ack_backlog
field of the sock structure is defined as unsigned short which limits the value to 16 bit and hence maximum value can be 65535
.
Root Cause
- RHEL 7 throws an error due to the below commit when setting
net.core.somaxconn
value greater than 65535.
commit 5f671d6b4ec3e6d66c2a868738af2cdea09e7509
Author: Roman Gushchin <klamm@yandex-team.ru>
Date: Fri Aug 2 18:36:40 2013 +0400
net: check net.core.somaxconn sysctl values
It's possible to assign an invalid value to the net.core.somaxconn
sysctl variable, because there are no checks at all.
The sk_max_ack_backlog field of the sock structure is defined as
unsigned short. Therefore, the backlog argument in inet_listen()
shouldn't exceed USHRT_MAX. The backlog argument in the listen() syscall is truncated to the somaxconn value. So, the somaxconn value shouldn't exceed 65535 (USHRT_MAX). Also, the negative values of somaxconn are meaningless.
before:
$ sysctl -w net.core.somaxconn=256
net.core.somaxconn = 256
$ sysctl -w net.core.somaxconn=65536
net.core.somaxconn = 65536
$ sysctl -w net.core.somaxconn=-100
net.core.somaxconn = -100
after:
$ sysctl -w net.core.somaxconn=256
net.core.somaxconn = 256
$ sysctl -w net.core.somaxconn=65536
error: "Invalid argument" setting key "net.core.somaxconn"
$ sysctl -w net.core.somaxconn=-100
error: "Invalid argument" setting key "net.core.somaxconn"
This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.
Comments