gamedig / node-gamedig

Query game servers and not only! Node.JS/Deno/Bun or Bash (via the CLI).
https://www.npmjs.com/package/gamedig
MIT License
607 stars 147 forks source link

bug: maxRetries will always try at least twice #640

Open dgibbs64 opened 1 month ago

dgibbs64 commented 1 month ago

Describe the bug When I set maxRetries to 1 or 0 gamedig will still retry at least twice sometimes 3 times.

Steps To Reproduce set maxRetries to 1 or 0 and see at least 2 failed attempts

Expected behavior gamedig should try only once

        const gamedigData = await GameDig.query({
          type: protocol,
          host: ip,
          port: portToTry,
          requestRules: true,
          maxRetries: 1,
          socketTimeout: 750,
        });

Error: Failed all 3 attempts

mmorrisontx commented 1 month ago

For some reason, in v5, maxAttempts was renamed to maxRetries, but the behaviour wasn't changed, so maxRetries still really means maxTries. If you could set it to 0 (which you can't) it wouldn't try the query at all.

Note that the number of attempts is not the same as the number of tries. One try may contain three attempts if it has to try three different ports.

cetteup commented 1 month ago

The later part can be addressed by using the givenPortOnly option, which I would highly recommend if you know the correct port or implemented you own "ports to try" logic outside of gamedig.

dgibbs64 commented 1 month ago

I think slightly modifying the log output to clarify what it has done might save any misunderstanding. Something like Error: Failed all 1 attempts with 2 ports tried might be a good idea.