ERROR: too many active timers (20)

With each request, my Agent creates a timer that will timeout if no response arrives from the Device. That way, all requests can be confident of a response, even if it is to say that the Device didn’t respond.

Looks like I’ve been a bit too lax with keeping track of the number of timers I’m using. If my imp gets a lot of requests in close succession, I run out of timers. However, my Agent doesn’t really detect it, as it seems it’s only reported to the server log. It was by chance that I spotted the error recently.

The easy way for me to deal with it is to have a API call that gives me the number of timers remaining. Any chance of extending the API to support it. I could keep a counter, decrementing each time I create a timer and incrementing when the timer expires (or is cancelled). But that’s a bit of a pain when I use timers all over the place.

Can I be confident that this number (which seems arbitrary) will stay the same? If so, I’ll set a limit and queue any other requests until the dispatched requests are completed.

The limit is mentioned on the imp.wakeup page, but what isn’t mentioned is that the returned timer handle will be null if you try to exceed that limit.

Could you create a single timer that checks timeouts. In an array or table keep a list of the requests and their associated time of creation.?

I saw this technique in Beardedinventor’s example of handling http requests in the agent.

It’s possible that we might one day adjust that number upwards, but it’s basically unimaginable that we’d adjust it downwards, because that could break existing code. So you can safely use it to set your own limit if need be.

Peter