crossbario / autobahn-python

WebSocket and WAMP in Python for Twisted and asyncio
https://crossbar.io/autobahn
MIT License
2.48k stars 766 forks source link

Leaving a Component-attached session or stopping a Component causes infinite connection loop #1188

Open JustinTArthur opened 5 years ago

JustinTArthur commented 5 years ago

If a router replies to Autobahn's goodbye with a standards-compliant response like wamp.close.goodbye_and_out, the Component establishes a new connection. This will continue in an infinite loop.

The router's goodbye reply results in the protocol's success callback firing a new "leave" event. This triggers the Component's leave handler, which considers any leaving reason beyond wamp.close.normal to be an error, triggering a new connection somewhere downstream in the Component behaviors.

meejah commented 5 years ago

It seems like adding wamp.close.goodbye_and_out to the list of "close messages that are considered normal and final" is a good idea.

What about wamp.close.system_shutdown, wamp.close.close_realm and wamp.close.system_shutdown? Conversely, maybe any wamp.close.* should be considered fine and normal and only wamp.close.protocol_violation should be considered an error?

JustinTArthur commented 5 years ago

Error or not, we may still want to stop reconnection behavior after we've sent our own goodbye.

meejah commented 5 years ago

A work-around for now is to pass an is_fatal predicate function that returns True for any of the ApplicationError strings you want (beyond wamp.close.normal which will already end the re-connections).

meejah commented 5 years ago

Oh, and there's also Component.stop which should call .leave() on a session (if there is one) and then stop the component re-connecting etc (and once all the Components given to run are stopped, the process should exit).