tzhf / chatguessr

A Twitch chatbot for GeoGuessr.
https://chatguessr.com
MIT License
38 stars 9 forks source link

"Cannot read properties of undefined (reading 'rounds')" on the first round after starting CG #68

Open tzhf opened 3 months ago

tzhf commented 3 months ago

The issue only occurs at the very first round after launching CG, and does not occur for everyone. However it works just fine and does not require any restart or refresh, so it's not a big problem, but still.

Even if i think i know why it happens, I am not able to reproduce it.

It is the same error we got when GeoGuessr started to require cookies to their /api/v3/games/id endpoint. When they start the first round after launching the app, the first "fetchSeed()" request fails, so at this point Game.seed is undefined.

This is probably related to the cookies, but like i said i'm unable to reproduce it, unless by deliberately providing wrong cookies, but the question is: why the very first fetchSeed() request fails, leading to that error, but we still manage to get the seed probably from "refreshSeed()". My guess is that first request has bad/outdated cookies, second request has good ones.

Of course ideally we would like to prevent starting a game if we fail to fetch the seed, but it used to work just fine before we needed to attach cookies to that request.

image

tzhf commented 2 months ago

Note for later: The error occured randomly while developping, got that axios error:

AxiosError: read ECONNRESET
    at AxiosError.from (C:\Users\Administrator\Desktop\chatguessr\node_modules\axios\dist\node\axios.cjs:836:14)
    at RedirectableRequest.handleRequestError (C:\Users\Administrator\Desktop\chatguessr\node_modules\axios\dist\node\axios.cjs:3086:25)
    at RedirectableRequest.emit (node:events:514:28)
    at eventHandlers.<computed> (C:\Users\Administrator\Desktop\chatguessr\node_modules\follow-redirects\index.js:38:24)
    at ClientRequest.emit (node:events:514:28)
    at TLSSocket.socketErrorListener (node:_http_client:495:9)
    at TLSSocket.emit (node:events:514:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21)
    at Axios.request (C:\Users\Administrator\Desktop\chatguessr\node_modules\axios\dist\node\axios.cjs:3876:41)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Lr (C:\Users\Administrator\Desktop\chatguessr\.vite\build\main.js:5:4821)
    at async kr.ie (C:\Users\Administrator\Desktop\chatguessr\.vite\build\main.js:6:5108)
    at async kr.start (C:\Users\Administrator\Desktop\chatguessr\.vite\build\main.js:6:1700) {
  syscall: 'read',
  code: 'ECONNRESET',

We might want a retry when it occurs as suggested here: https://www.squash.io/how-to-fix-error-econnreset-in-nodejs

tzhf commented 2 months ago

Added retries for fetchSeed () in https://github.com/tzhf/chatguessr/commit/95961bee1ec40460dea9d0f0ced23c6333befd95 ECONNRESET errors are quite rare so 3 retries should be enough. As said above, ideally we would like to handle errors when game.seed is undefined if we fail to fetch the seed.