Catch Downlink disconnected

Objective:

I am encountering intermittent disruptions in my application, specifically an anvil.server.RuntimeUnavailableError: Downlink disconnected error that arises during the execution of background tasks.

Challenge:

I’m searching for a reliable method to handle this error gracefully. Traditional try...except blocks appear to be ineffective in capturing this specific exception, leading to an abrupt and unmanaged cessation of the server connection.

Attempts and Observations:

  • I’ve implemented standard exception handling techniques, yet they seem to be bypassed by this particular error.
  • The sporadic nature of the RuntimeUnavailableError makes it challenging to anticipate and mitigate.
  • The issue isn’t rooted in the code logic, as the error occurs due to an external factor - the server connection being lost.
  • The primary concern is that the server becomes unresponsive without any recovery mechanism in place, which is problematic for maintaining a seamless operational flow.

Seeking Guidance:

I would appreciate any insights or suggestions on how to effectively intercept this RuntimeUnavailableError and ensure that the application can either resume operations or fail gracefully, minimizing disruption and enhancing user experience.

1 Like

First:
Are you calling the background task directly that is a function in your uplink code running on another machine? If so, don’t do that. Have a wrapper function that is a background task on the server module call the uplink code. (It can run as long as it wants on uplink)

Second:
I have heard @david.wylie Talk about creating (in the server module) an identical named callable function as his uplink code that just raises an error when called.

The uplink function gets registered when it’s run on your external machine so it should take priority over the server module with the same-named callable function.

This way if the uplink is disconnected, anvil will “fall back” to the server module and raise an error or return something that tells the user it is disconnected instead of raising the uncatchable RuntimeUnavailableError .

1 Like

Thanks, for the reply.

However, this error happens not with Uplink.

I get this error, in Anvil Server.

1 Like

You have probably already reviewed the forum for related posts, but for the sake of others, here are some I’ve found, mostly similar reports and questions regarding the nature of the error (as opposed to your more specific question about how to handle it):

The first one’s from a few years back, and other more recent threads confirm the existence of an error message now that explicitly mentions running out of memory, so maybe that’s now less likely to be a cause of this error message?

Another older one:

More recent:

1 Like