crossbario / crossbario/autobahn-python

Bad error handling in the autobahn_autoreconnect file

Open
#1,618 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.5k
Forks
768
PR merge metrics
No merged PRs in 30d

Description

My team and I noticed the following alarming behavior of autobahn’s retry policy when an invalid/bogus URL is given for the _connect function in the init.py file:

• Instead of implementing the default retry policy of trying to reconnect in 1, 2, 4, 8, 16, etc seconds, the _connect function is instead spamming the server with retry requests multiple times per second!
• This is due to the fact that the _reconnect function does not have a delay or retry policy
o If the retry fails, _reconnect calls the _connect function immediately, which then calls _reconnect right away when that fails, and so on.
• This leads to a system spamming our corporate network with a flood of connection requests, which causes the network to prevent any other systems from connecting. This is very troublesome as it practically prevents any of our systems from connecting to the network!
• The python version we are using is 3.6.2

We are trying to understand why the invalid URL case does not get handled as a retry (except OSError) but rather that the reconnect happens instantaneously. The affected source code is shown below

@asyncio.coroutine
def _connect(self):
self._active_protocol = None
self._retry_strategy.reset_retry_interval()
while True:
try:
_, protocol = yield from self._loop.create_connection(self._transport_factory, self._host, self._port, ssl=self._ssl)
protocol.is_closed.add_done_callback(self._reconnect)
self._active_protocol = protocol
return
except OSError:
print('Connection failed')
if self._retry_strategy.retry():
retry_interval = self._retry_strategy.get_retry_interval()
print('Retry in {} seconds'.format(retry_interval))
yield from asyncio.sleep(retry_interval)
else:
print('Exceeded retry count')
self._loop.stop()
raise ExceededRetryCount()

            self._retry_strategy.increase_retry_interval()

def _reconnect(self, f):
    # Reconnect
    print('Connection lost')
    if not self._closing:
        print('Reconnecting')
        asyncio.async(self._connect(), loop=self._loop)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in init.py with the _connect and _reconnect functions, then trace how an invalid URL moves between them and how the retry strategy is applied. Reproduce the invalid-URL case and verify that reconnect attempts follow the existing retry intervals instead of occurring repeatedly within seconds.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
networking
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.