Skip to content

Fix crash and stuck rate limit when the PoE login can't be refreshed - #2604

Merged
Wires77 merged 2 commits into
PathOfBuildingCommunity:devfrom
zediir:fix-rate-limiter-stuck-after-failed-request
Dec 2, 2026
Merged

Wires77 merged 2 commits into
PathOfBuildingCommunity:devfrom
zediir:fix-rate-limiter-stuck-after-failed-request

Conversation

@zediir

@zediir zediir commented Nov 29, 2026 •

Copy link
Copy Markdown
Contributor

Description of the problem being solved:

When the PoE API rejects the saved access token and refreshing it fails (for example the refresh token was revoked by signing in from another install, or PoB was left open past the token's expiry while offline), clicking Start in Character Import crashes:

In download callback: Classes/PoEAPI.lua:192: attempt to index local 'response' (a nil value)
stack traceback:
    Classes/PoEAPI.lua:192: in function 'callback'
    Classes/PoEAPI.lua:152: in function 'callback'
    Classes/PoEAPI.lua:44: in function 'callback'
    Launch.lua:317: in function <Launch.lua:316>

DownloadWithRefresh calls back without a response when the refresh fails, and DownloadWithRateLimit then reads response.header.

The crash also leaves the rate limiter stuck. The request was recorded but its response headers were never read, so TradeQueryRateLimiter:NextRequestTime treats the policy as waiting for its first response and returns its long cooldown (a timestamp in 2032). After signing in again, every character list request is refused with "Requests are being sent too fast, try again in 160555682 seconds" until PoB is restarted.

Changes (two commits):

  • TradeQueryRateLimiter:NextRequestTime blocks a policy with unknown limits only while one of its requests is still pending, instead of whenever a request was ever recorded.
  • PoEAPI:DownloadWithRateLimit passes the error on when there is no response. The Import tab then shows "Not authenticated" and the Authorize button.

The two belong together: with only the PoEAPI change, the crash is gone but the rate limiter still blocks every request after signing in again.

Steps taken to verify a working solution:

  • Added specs: one replays the failed refresh through DownloadCharacterList (on dev it fails with the stack trace above), two cover NextRequestTime with a pending and a finished request. The full busted suite passes in the pathofbuilding-tests image (906 successes).
  • Reproduced manually in a dev-mode install by putting a fake token in src/Settings.xml: <Accounts tokenExpiry="<a time in the future>" lastToken="fake-access-token" lastRefreshToken="fake-refresh-token" lastRealm="PoE2"/>. New build, Import/Export Build tab (shows "Authenticated"), click Start.
    • Before: the error above. After dismissing it and authorizing with a real account, the character list is refused with the rate limit message.
    • After: no error, the status shows "Not authenticated". Authorizing with a real account in the same session then lists and imports characters.

Link to a build that showcases this PR:

Not build-specific.

Before screenshot:

Clicking Start with a token that can't be refreshed:

before1

After dismissing the error and signing in again:

before2

After screenshot:

Clicking Start with a token that can't be refreshed:

after1

After signing in again in the same session:

after2

I made this with the help of an AI assistant (Claude). I don't have much Lua experience, but I have read the changes and understand what each line does and why.

Until a response's headers have been parsed, NextRequestTime blocked a policy
whenever any request had ever been recorded for it. A request that finished
without its headers being read (e.g. the PoE login could not be refreshed)
therefore blocked the policy until 2032, so character import refused every
request until Path of Building was restarted, even after signing in again.

Block only while a request is still pending, which is what the long cooldown
is for.
When the PoE API rejected the access token and the refresh failed,
DownloadWithRefresh called back without a response, and
DownloadWithRateLimit then indexed response.header:

  In download callback: Classes/PoEAPI.lua:192: attempt to index local 'response' (a nil value)

Pass the error on instead, so the Import tab shows "Not authenticated" and the
Authorize button.
@zediir
zediir marked this pull request as ready for review November 29, 2026 17:23
@Wires77 Wires77 added the bug Something isn't working label Dec 2, 2026
@Wires77
Wires77 merged commit 7d3ed1c into PathOfBuildingCommunity:dev Dec 2, 2026
5 checks passed
@zediir
zediir deleted the fix-rate-limiter-stuck-after-failed-request branch December 2, 2026 10:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants