pokebot-gen3 icon indicating copy to clipboard operation
pokebot-gen3 copied to clipboard

WEB API - get items hangs after first api call

Open Zelak312 opened this issue 9 months ago • 0 comments

The first API call to items works but the consecutive calls only hangs

How to reproduce

  • Call the GET /items once
  • Call it again and it should hang and never give back a repsonse (All requests afterwards don't receive a response either)

While investigating this issue. I saw that this piece of code looked at the age in seconds of the cached value https://github.com/40Cakes/pokebot-gen3/blob/14b7bef57ab26d7f12109f4465b6928ae96bc543/modules/web/http.py#L129-L134

From what I found, the items endpoints hangs because the age in seconds never resets which causes an infinite loop

While looking through the code with a debugger, I found that it happens because of this if statement https://github.com/40Cakes/pokebot-gen3/blob/14b7bef57ab26d7f12109f4465b6928ae96bc543/modules/state_cache.py#L143-L146

For the first API call, the statement is True which executes the line self._item_bag.value = item_bag That line will then execute the generic value setter which resets the self.time of the StateCacheItem which makes it work

On the other API calls after that, the statement is False which essentially doesn't execute the generic value setter, that makes it so the StateCacheItem keeps it's old time and causes the infinite loop

The same issue happens with ItemStorage, not just the ItemBag

I wasn't sure what would be considered to best way to fix this issue so I decided to just create an Issue and not a pull request but I could always open one with a fix if needed.


Just a little recommendation I would like to make. Those while loops could have a stopping condition after a certain amount of time / tries and send an error response back so infinite loop can't occur

Zelak312 avatar May 09 '24 21:05 Zelak312