actualbudget / actualbudget/actual
[Bug]: GoCardless token expires before completion on long imports
- Lingua principale
- TypeScript
- Stelle
- 28.8k
- Fork
- 3k
- Merge medio
- 2g 11h
- PR unite (30g)
- 65
Descrizione
### Verified issue does not already exist?
- [X] I have searched and found no existing issue
- [X] I will be providing steps how to reproduce the bug (in most cases this will also mean uploading a demo budget file)
### What happened?
Hello,
When importing accounts with a long history (390 days) and a lot of transactions, the GoCardless JWT token actually expires before the sync completes, but isn't refreshed in all the operations that make API calls to GoCardless, leading to an exception in the logs and the UI crashing (and the account never being imported).
Here's the relevant part of the stacktrace:
```
2024-10-06T21:43:11.762Z info: POST 200 /sync/sync
Error /gocardless/get-accounts InvalidGoCardlessTokenError: Token is invalid or expired
at handleGoCardlessError (file:///app/src/app-gocardless/services/gocardless-service.js:46:13)
at Object.getDetailedAccount (file:///app/src/app-gocardless/services/gocardless-service.js:413:7)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async file:///app/src/app-gocardless/services/gocardless-service.js:152:25
at async Promise.all (index 0)
at async Object.getRequisitionWithAccounts (file:///app/src/app-gocardless/services/gocardless-service.js:150:30)
at async file:///app/src/app-gocardless/app-gocardless.js:68:9 {
```
I imagine this can crash in multiple places, but we can see for example in the [getDetailedAccount](https://github.com/actualbudget/actual-server/blob/master/src/app-gocardless/services/gocardless-service.js#L405) call, it doesn't call [setToken](https://github.com/actualbudget/actual-server/blob/master/src/app-gocardless/services/gocardless-service.js#L79).
I don't see any downsides to calling setToken before each API call (especially if the expiration time is cached so it doesn't need to be decoded every time), so that should fix the issue, unfortunately I don't have the infrastructure setup to test the fix myself.
Thanks.
### Where are you hosting Actual?
Docker
### What browsers are you seeing the problem on?
Any
### Operating System
Any
Guida per i contributori
Apri la guida per i contributori
Direzione di ricerca
Start in src/app-gocardless/services/gocardless-service.js, especially getDetailedAccount, setToken, and getRequisitionWithAccounts, then trace the other GoCardless API call paths shown by the stack trace. Verify that long imports refresh the token before each required API call and complete without an InvalidGoCardlessTokenError or UI crash.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- javascript, node.js
- Ambito
- api, backend
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Specificata chiaramente
- Idoneità per principianti
- 35/100