Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

bug: Timeouts not triggering for TCP queries #611

Closed
cetteup opened this issue Aug 16, 2024 · 2 comments · Fixed by #610
Closed

bug: Timeouts not triggering for TCP queries #611

cetteup opened this issue Aug 16, 2024 · 2 comments · Fixed by #610
Labels

Comments

@cetteup
Copy link
Contributor

cetteup commented Aug 16, 2024

Describe the bug
When using a TCP-based query protocol, such as the battlefield one, timeouts do not trigger as expected. Socket timeout seems to to not trigger at all, attempt timeout gets logged, but does not acually abort the connection attempt.

Steps To Reproduce
Using gamedig 5.1.1, run

gamedig --type battlefield4 62.104.17.57:47200 --socketTimeout 1640 --maxRetries 2 --givenPortOnly

Expected behavior
Run two attempts against the given IP/port combination, which fail because the TCP connect times out after 1640 ms each. The total runtime should be roughly 2 x 1640 = 3280ms.

Screenshots or Data
Using 5.1.1, the entire command runs for over two minutes.

time gamedig --type battlefield4 62.104.17.57:47200 --socketTimeout 1640 --maxRetries 2 --givenPortOnly
{"error":"Failed all 2 attempts"}
gamedig --type battlefield4 62.104.17.57:47200 --socketTimeout 1640 2 0,56s user 0,11s system 0% cpu 2:19,83 total

The failed attempts get logged after ~20 seconds, which would 2x the default attempt timeout. But it then hangs for two minutes. Running it with --debug shows that the connection timeout only triggers right before the command exits (after >2 mintues).

Q#0 TCP Error: Error: connect ETIMEDOUT 62.104.17.57:47200
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16)
Q#0 TCP Closed
Q#0 Error in promise: Error: TCP Connection Refused
Q#1 TCP Error: Error: connect ETIMEDOUT 62.104.17.57:47200
at TCPConnectWrap.afterConnect [as oncomplete] (node:net:1607:16)
Q#1 TCP Closed
Q#1 Error in promise: Error: TCP Connection Refused

Additional context
I had a quick look in the debugger, looks like the this.registerRtt call is causing the 2-minutes hang, as a breakpoint in the line below (which seemingly set's up the socket timeout) only fires after 2 minutes.

const connectionPromise = new Promise((resolve, reject) => {
socket.on('ready', resolve)
socket.on('close', () => reject(new Error('TCP Connection Refused')))
})
await this.registerRtt(connectionPromise)
connectionTimeout = Promises.createTimeout(this.options.socketTimeout, 'TCP Opening')
await Promise.race([
connectionPromise,
connectionTimeout,
this.abortedPromise
])
return await fn(socket)

Running the equivalent command using 4.3.2 works as expected

time gamedig --type bf4 62.104.17.57:47200 --socketTimeout 1640 --maxAttempts 2 --givenPortOnly
{"error":"Failed all 2 attempts"}
gamedig --type bf4 62.104.17.57:47200 --socketTimeout 1640 --maxAttempts 2 0,14s user 0,07s system 5% cpu 3,455 total

@CosminPerRam
Copy link
Member

This weekend I was very busy because I was switching places and if I would have had taken a look at this earlier (as you made this issue roughly right after my PR), I could have made the fix faster, my bad.

@cetteup
Copy link
Contributor Author

cetteup commented Aug 20, 2024

No rush. I had already reverted back to the 4.x version in "prod".

Thanks for addressing the issue. Hope your move went well! 📦

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants