I don’t know if this is a bug. Perhaps it’s a known limitation and we need to live with it.
I don’t think it’s a big problem, I can live with it, but I thought I would report it anyway.
Anvil says AppOfflineError
which makes me think the problem is on the server or on the connection, instead it’s on the client. Perhaps AppOfflineError
is intended to catch all the server call problems, so it’s OK.
I have a form with a timer with interval set to 5 seconds that checks if the current document has been modified by another user. It’s a simple server call that compares the timestamp of the current document with the timestamp of the same document on the database.
The form has a button that runs an optimization on the client that can take a long time. In order to prevent the browser from showing the message about the non responding page, I have split the optimization in smaller discrete steps and there is a second timer with interval set to 0.01 that executes the next step of the optimization. Each step can take anywhere between a few seconds and 1 minute or more, so in theory I could see the non responding page warning anyway, but it’s unlikely.
Everything works well, but once in a while I see the error AppOfflineError: Connection to server failed (1006)
.
I think this happens when the first timer calls the server, then the second timer takes over to run the next step and it takes longer than the server call likes.
I can disable the 5 second check while the optimization is running, then reenable it at the end. This should fix my form.
Here is a simple app that reproduces the problem:
https://anvil.works/build#clone:EUIRO2CQXVW3MABT=RSN2N47GT6G2OHB6EL66PHYF
Here is the output.
On the left the output from the slow timer. It starts with 21 second long tasks, then 22 seconds, etc.
On the right the output from the server call timer. It works if the slow task lasts less than 30 seconds, it fails if it lasts longer.