Intermittent Loading Issues with Custom Domain

Hello Anvil Community,

I’m experiencing an issue with my app where the production version is stuck at the loading screen, displaying the loading symbol indefinitely, and eventually ends with the error AppOfflineError: Connection to server failed (error). However, the debug version of the exact same app loads without any issues. Both branches of the app are identical in terms of code and configuration.

Here’s what I’ve observed:

  • When I open the production version of the app, the startup form is stuck at the loading symbol, and none of the components load.
  • The debug version of the app, which is identical to the production version, loads without any problems.
  • There are no issues with the network connection, as the debug version works fine.
  • I’m using the Professional plan.

I’ve tried clearing the browser cache, checking the browser console for errors, and verifying the server logs, but I haven’t been able to identify the cause of the issue. I’m wondering if this could be related to server latency, shared server resources, or some other factor specific to the production environment.

I have a few questions:

  1. What causes the AppOfflineError: Connection to server failed (error) error, and how can I prevent it from occurring?
  2. Would upgrading to a Business or Dedicated plan help eliminate this error and improve the performance and reliability of my app?

Is anyone else experiencing a similar issue? Any insights or suggestions would be greatly appreciated.

Thank you!

I wanted to add that the AppOfflineError: Connection to server failed (error) issue I mentioned earlier is intermittent in the production version of the app. If I keep refreshing the page, it will occasionally load successfully, but most of the time I get the error. It seems to work about 1 out of 15 times.

The debug version of the app doesn’t have this problem at all. It loads without any issues every time I try it.

@stucork

I’ve somewhat narrowed down the issue with my app hanging at startup. It seems (I think) to be caused by the anvil.users.get_user() function, which I call in the __init__ method. When this function is called, the app gets stuck at the loading symbol and eventually gives the AppOfflineError: Connection to server failed (error).

This issue only occurs in the production version of the app. The debug version, which has the same code and configuration, works fine.

Has anyone else experienced this issue with the anvil.users.get_user() function?

Hi @delvai,

Have you been able to reproduce this issue in any other apps? Are you able to create a minimal example that demonstrates the issue?

Hi @brooke

Unfortunately I haven’t been able to reproduce this issue in another app. Although I was able to isolate the problem to the anvil.users.get_user() line. If I move this line to the form_show event instead of __init__, that’s where the app hangs during startup instead. The problem is intermittent, so sometimes the app does load fine, but mostly it hangs on this line. When I try to open the debug version of the app, it seems to have no problem at all running this line. Also, this issue started happening 1-2 days ago. I tried it on older branches of the app as well from weeks ago, and the issue persists.

Does the app have a large amount of users?

@brooke

The app has around 200-300 registered users. I’d also like to note that both the debug and production versions of the app use the same database.

Also, when I preview the production version of the app within the Anvil IDE, the error doesn’t occur. However, when I access the live version of the app in a separate browser window or tab, the error happens.

I apologize for the confusion in my previous posts. Upon further investigation, I’ve discovered that the issue is not limited to the anvil.users.get_user() function. It appears that server calls, in general, are causing the app to hang at startup in the production version.

I want to clarify that this issue is intermittent, and it sometimes works fine, but most of the time, it hangs on server calls. The debug version of the app, which has the same code and configuration, works without any issues every time I try it. This issue does not occur either when running the app on the Anvil IDE.

I’m sorry for any confusion my previous posts may have caused.

@brooke

I’ve also ruled out connectivity issues as a potential cause, as this problem occurs for all of my users, regardless of their location. I’ve tried running a simple server function that only returns True, and the app constantly hangs at this function. Additionally, I’ve put a print statement at the top of the server module to see if one of the imports might be causing the issue, but the print statement doesn’t even run.

Also, to add another observation to my previous posts. I’ve noticed that during the times when the app does successfully load, all successive server calls are successful and there are no issues. However, if I refresh or open the app and it doesn’t succeed in that initial server call, it just does not work at all. I have to keep refreshing the app again and again until I get lucky and it succeeds at that first server call.

It seems that once the app manages to make a successful server call, it can continue to make server calls without any problems. But if it fails at that first server call, it gets stuck and doesn’t work until I refresh and it manages to make a successful server call.

Hi @delvai

We’re investigating this now, and we were able to reproduce the issue on the production version of your app. However, I see that you’ve just removed your custom domain, and now the issue isn’t happening for us. Are you still seeing the problem?

I believe I’ve been able to narrow down the problem further, and it appears to be related to the custom domain I’m using for my app.

I cloned the app, and the cloned version ran perfectly without any issues. However, when I switched the custom domain to point to the cloned app, the cloned app started experiencing the same hanging issue as the original app. When I switched the cloned app back to a public link, it started working again.

I want to emphasize that I did not make any changes to the custom domain settings on Cloudflare since first setting it up more than 5 months ago, but the issue seems to be specifically related to the custom domain, as the app works fine when accessed through a public link.

@daviesian

Yes, the issue is still happening. I removed the custom domain on the app because I figured I’d start using the new clone since it was working, but it also ended up not working as well when I connected it to the custom domain. What do you recommend I do?

@daviesian

edit: I just added the custom domain back to the original app

Hi @delvai

Thanks for the updates. Yes, I agree that the issue seems to be related to the DNS settings on your custom domain. Please can you update the domain to point to Anvil directly as described in the docs, then let us know whether you still see the issue? Thanks!

Thanks for the response. I can confirm that I followed the instructions in the Anvil documentation when setting up the custom domain for my app. The custom domain had been working perfectly fine for several months, and I hadn’t made any changes to the DNS settings since I first set it up.

The issue with the app hanging at startup during server calls only started occurring a couple of days ago, and I haven’t made any changes to the DNS settings or the app configuration that could have triggered this issue.

I just checked the DNS settings and everything seems okay. Is there anything else specifically that I should double-check in the DNS settings to ensure everything is configured correctly?

@daviesian

edit: when using the custom domain, the app actually seems to load okay (the components load correctly) until a server call is made, then that is when it hangs.

Your custom domain is not currently pointing to the Anvil IP address - 52.56.203.177. Please set it up to point to there, then it should work.

Currently I think it’s pointing to CloudFlare, who may easily have changed something about the way multiple connections are made, or something else.

This is it right?

@daviesian

The “Proxied” part means it’s going through Cloudflare (see their docs for an explanation). Changing it to “DNS only” will allow you to evaluate what happens without Cloudflare in the way.

Hi @meredydd,

Thank you for the suggestion. I have switched the proxy status from “Proxied” to “DNS only” in Cloudflare as you recommended. However, I’m still experiencing the same issue with the app hanging at startup during server calls. I’ve tested it multiple times, and the result is the same.

Is there anything else I should check or try to resolve this issue?

Additionally, I noticed the following error(one of a few new ones) in my browser console after switching the Proxy Status to DNS Only:

WebSocket connection to 'wss://[my_domain]/_/ws/?s=2CNQ63XFTAJZIW5HQ7LLG6E76F5OBLMT=OZCaTdyJSmqq-09iwlZTEeWPU8Tw' failed: An SSL error has occurred and a secure connection to the server cannot be made.

Could this be related to the issue I’m experiencing?

Highly appreciate the assistance.

I set it back to Proxied because on top of the app not loading, my users seem to be seeing this as well now after setting it it to DNS only.

I’m really at a loss right now, I haven’t done anything on my Cloudflare account to have caused this and my custom domain is far from being expired too. All of this literally started happening out of nowhere 3 days ago and I changed nothing. The app has been completely unusable since then and I have users who are still paying for my service.

I feel like I’m hitting a wall and there’s nothing I can do.

edit: and like I mentioned above, the problem is intermittent. 1 out of 10-15 times, the app loads properly. So this tells me it is connected to the right Anvil IP address.

edit: It seems to have fixed itself. I’ll keep observing and post an update if it starts acting up again.

Hi - it’s happening again. Production version no longer loading. Just started a few hours ago. And again, I changed nothing that could have caused this…

@meredydd