Displaying Callback Errors to the Client

I’m looking for advice on the best way to display callback errors to the client when the web server times out or fails to respond.

Setup:
We are using gunicorn server with a timeout which kills worker threads if they exceed X seconds. When the worker thread is killed the connection is forcibly closed before the callback completes. This is convenient as it prevents a handful of long callbacks from locking up all of the worker processes.

What happens:
Currently when a callback fails (due to timeout, but sometimes other reasons) the html element silently returns to its previous state after logging to the developer console. For something wrapped in a dcc.Loading object, this tends to look like the load succeeded, however the contents will be stale data or other output that doesn’t make sense.

Desired behavior:
Be able to define “on callback failure” what to display inside the dcc.Loading object or some other mechanism to alert the user that something went wrong.

Any advice is greatly appreciated.

Great question - This isn’t currently supported in an official or out of the box way.

You might be able to make a custom component like dcc.Loading that inspects the contents of the previous render with the next render and displays an error message if they happen to be the same. That’s a big assumption, as outputs could have the same value across multiple updates in a non-error case.

It would be neat to have some kind of dcc.Error component that could handle known thrown exceptions in callbacks (without needing to handle it yourself via a custom error message that updates the children property) as well as uncaught exceptions elsewhere in the network stack.

For the particular use case of timeouts, you may be interested in the forthcoming long_callback functionality. See the recent posts on dash-labs.

I have also been looking for this kind of functionality, but I haven’t found a good solution. Typically I end up adding an additional output (e.g a div) to display the error. But your suggested syntax would be much nicer.

Thanks for the replies.

@chriddyp

It would be neat to have some kind of dcc.Error component

Yeah that sounds like a very useful concept, I would definitely be a user of such a component.

you may be interested in the forthcoming long_callback

Yep, I have been following that. It looks promising. Although it doesn’t eliminate the usefulness of a network callback error component.

@Emil

Typically I end up adding an additional output (e.g a div) to display the error

I’m not clear on how this can display a network callback error. Any clarity would be appreciated.

Another thought - You might be able to hack in something with the request_post hook

https://dash.plotly.com/external-resources

You might be able to include a 3rd party notifications JS library and trigger an error notification in JS with that request hook. Or even find the ID of the component by inspecting the request and display an overlay on that div with vanilla JS

1 Like

You might be able to include a 3rd party notifications JS library and trigger an error notification in JS with that request hook.

This seems like an interesting approach that should work. I was a little hesitant to go down the JS route so for now I decided to preemptively timeout the computation within the callback before the worker gets killed and return gracefully. This catches most errors we see (but not all).

Thanks for the advice all.