How to simulate uplink disconnect?

I need to debug my uplink server code for uplink disconnection. How can I do that? I tried adding the wss.anvil.works/uplink url to my firewall to block it but it still seemed to be working. I also pinged the url to get the IP then added that to my firewall block list but still my server code ‘anvil.server.callable & anvil.server.background_tasks’ methods are being called from the background tasks. I want to simulate the uplink breaking then coming back. I could take down port 443 but that would take down other things. Thanks

What about unplugging the network cable / disconnecting from wifi?

That’s closer to a real world problem, where the connection is lost at some random time rather than prevented to begin with.

At first I was like… Well yeah! but then I was like Well no! I don’t think there has ever been a time that someone else disconnected my network cable. Funny right? I do see your point. I did think of this but it would take everything down. I wan’t to see how the rest of the code behaves like the Auth code and exception handling, even the Requests module when only the uplink goes down.

I will try it as a test case. Also, thank you for being the first to reply. I thought I had asked something evil. Like social leprosy. Have a great day!

Yuck! I pulled the cable (turned off WiFi) and my app puked all over itself. The connection came back when I turned on the wifi but the app is sitting brain dead in memory. None of the background tasks from the Anvil side are firing on the uplink side. On the Anvil side the logs say the uplink server has been disconnected although the uplink side app says the connection came back. (as shown below). Is this recoverable without having to restart the application?

Anvil websocket closed (code 1006, reason=Going away)
Exception in thread Thread-2:
Traceback (most recent call last):
File “/Users/jamespierce/Documents/myapp/lib/python3.7/site-packages/anvil/server.py”, line 283, in call
return _do_call(args, kwargs, fn_name=fn_name)
File “/Users/jamespierce/Documents/myapp/lib/python3.7/site-packages/anvil/server.py”, line 275, in _do_call
return _threaded_server.do_call(args, kwargs, fn_name=fn_name, live_object=live_object)
File “/Users/jamespierce/Documents/myapp/lib/python3.7/site-packages/anvil/_threaded_server.py”, line 357, in do_call
raise _server._deserialise_exception(r[“error”])
anvil._server.AnvilWrappedError: ‘Connection to Anvil Uplink server lost’

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py”, line 926, in _bootstrap_inner
self.run()
File “/usr/local/Cellar/python/3.7.5/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py”, line 870, in run
self._target(*self._args, **self._kwargs)
File “/Users/jamespierce/Documents/myapp/lib/python3.7/site-packages/anvil/server.py”, line 139, in heartbeat_until_reopened
call(“anvil.private.echo”, “keep-alive”)
File “/Users/jamespierce/Documents/myapp/lib/python3.7/site-packages/anvil/server.py”, line 286, in call
raise _server._deserialise_exception(e.error_obj)
anvil._server.AnvilWrappedError: ‘Connection to Anvil Uplink server lost’

Reconnecting Anvil Uplink…
Connecting to wss://anvil.works/uplink
Reconnection failed. Waiting 10 seconds, then retrying.
Reconnecting Anvil Uplink…
Connecting to wss://anvil.works/uplink
Reconnection failed. Waiting 10 seconds, then retrying.
Reconnecting Anvil Uplink…
Connecting to wss://anvil.works/uplink
Reconnection failed. Waiting 10 seconds, then retrying.
Reconnecting Anvil Uplink…
Connecting to wss://anvil.works/uplink
Anvil websocket open
Authenticated OK

I have computers with uplink scripts running 24/7. I often see connection problems, but they are almost always able to reestablish a connection without problem. Almost = less than once a month they don’t.

Perhaps you have another script on another computer that registered functions with the same name on the same app?

Good to know! I will look into it. Thanks!

Looks like it does recover but not all the time. Thanks.

If you notice a pattern on the traceback that appears when it recovers and when it doesn’t, please send them to the Anvil team and it will help troubleshoot the problem.

1 Like

Will do! Thanks again!

If the Uplink script has reconnected successfully, anvil.server.calls into it should work without needing to reload the app in the browser, so there’s a potential bug here.

Would you mind letting us know more detail about your app so we can see what’s going on? What is your app doing that stops working when the Uplink reconnects?