question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

run_forever()'s restart condition never met

See original GitHub issue

in this loop on line 208 of stream.py, self._running is never set to false in the exception. retries starts at 0, then incremented in the exception. This has it compare 1>3 which is false. This means that self._running is never set to false. Then in finally block on line 226, the break statement on line 228 will never be reached. Wouldn’t this stop it from restarting on the next pass of the loop?

        while True: # stream.py - line 208
            try:
                if not self._running:
                    await self._start_ws()
                    self._running = True
                    retries = 0
                    await self._consume()
            except websockets.WebSocketException as wse:
                retries += 1
                if retries > int(os.environ.get('APCA_RETRY_MAX', 3)):
                    await self.close()
                    self._running = False
                    raise ConnectionError("max retries exceeded")
                if retries > 1:
                    await asyncio.sleep(
                        int(os.environ.get('APCA_RETRY_WAIT', 3)))
                log.warn('websocket error, restarting connection: ' +
                         str(wse))
            finally:
                print(retries)
                if not self._running:
                    break
                await asyncio.sleep(0.01)```

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:1
  • Comments:7 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
Chrisrdouglascommented, Jul 10, 2021

@srgustafson8 Thank you for making a pull request with a fix. As for the 1006 error, I’m wondering if that has something to do with the way web sockets are implemented server side. If I hadn’t already switched to Polygon for my needs then I’d use Wireshark to sniff the traffic on my machine and start trouble shooting the issue that way.

Alpaca really needs engineers who are testing and using the software they’re providing 😕

1reaction
srgustafson8commented, Jul 9, 2021

I have been taking a look at this and while the cause of the 1006 errors remain a mystery to me, the reconnect should kick in after one and get you going again.

I’m not a python expert, but @Chrisrdouglas assessment looks along the right lines. There was an update at some point since which brought await self._consume() out of the if not self._running: statement, but that doesn’t seem to reconnect the websocket in the case of a 1006 error.

I’ll raise a pull request with a fix and see what the maintainers think.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Python "while" Loops (Indefinite Iteration)
Iteration means executing the same block of code over and over, potentially many times. A programming structure that implements iteration is called a...
Read more >
While Loops
To use this loop variable, we'll need to give it a start value, an update action, and a continuing condition. All three need...
Read more >
Why do I get a RecursionError using either while or if indefinite ...
Therefore your condition is never met and main() is called infinitively. – Nils. Nov 18, 2019 at 14:21.
Read more >
Writing Functions in Python.txt - GitHub
Begin by getting the docstring for the function count_letter(). ... If you've ever seen the "with" keyword in Python and wondered what its...
Read more >
Loops Flashcards by S Jammy - Brainscape
Study Loops flashcards from S Jammy's class online, or in Brainscape's iPhone or Android app. ... Infinite loops occur when stop conditions are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found