[1.1.5/Linux] RCON connection problems related to TCP SYN cookies

This subforum contains all the issues which we already resolved.
blahfasel2000
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Sat Mar 28, 2020 2:10 pm
Contact:

[1.1.5/Linux] RCON connection problems related to TCP SYN cookies

Post by blahfasel2000 »

When disabling TCP SYN cookies on my Linux system (by setting the net.ipv4.tcp_syncookies sysctl to 0), connections to the Factorio RCON port are no longer possible. The connect just hangs until it eventually times out while the connection shows as SYN_SENT in netstat. Note that all tests were done through localhost (127.0.0.1), there's no firewall involved that could potentially interfere.

Using strace I tracked it down to the listen() system call that Factorio uses on the RCON server socket:

Code: Select all

[pid 10058] setsockopt(19, SOL_SOCKET, SO_RCVBUF, [262144], 4) = 0
[pid 10058] setsockopt(19, SOL_SOCKET, SO_REUSEADDR, [1], 4) = 0
[pid 10058] bind(19, {sa_family=AF_INET, sin_port=htons(9999), sin_addr=inet_addr("0.0.0.0")}, 16) = 0
[pid 10058] listen(19, 0)               = 0
Factorio uses 0 for the second parameter (backlog), which on recent Linux kernels (5.4.0 in my case) causes the observed failure.

Changing the second listen() parameter into a 1 fixes the problem, as I confirmed with a small LD_PRELOAD wrapper for the listen() call.

On the other hand with SYN cookies enabled there's another problem. When sending small RCON packets everything works fine, but with larger packets (>2kB) there's a significant latency (>200ms). This was noticed by the developers of Clusterio 2.0. Investigations lead to some obscure problems with TCP window scaling, which are triggered by the 0 backlog in the listen() call and Linux's subsequent use of SYN cookies as well. Again changing the listen() parameter to a positive value through LD_PRELOAD fixes the problem.

One could argue that both are potentially bugs in the Linux kernel, however changing the backlog parameter in Factorio should be a simple and safe fix for both problems.
Attachments
factorio-current.log
(4.14 KiB) Downloaded 133 times
Oxyd
Former Staff
Former Staff
Posts: 1428
Joined: Thu May 07, 2015 8:42 am
Contact:

Re: [1.1.5/Linux] RCON connection problems related to TCP SYN cookies

Post by Oxyd »

Okay, I changed it to 4096 in 1.1.6.
blahfasel2000
Long Handed Inserter
Long Handed Inserter
Posts: 50
Joined: Sat Mar 28, 2020 2:10 pm
Contact:

Re: [1.1.5/Linux] RCON connection problems related to TCP SYN cookies

Post by blahfasel2000 »

Thanks :-)
Post Reply

Return to “Resolved Problems and Bugs”