kraken broker/live-trade-ctl roaming support is borked, ws subscribe layer raises 'ESession:Invalid session'... #14

Open
opened 2024-12-04 01:19:57 +00:00 by goodboy · 1 comment

Moving between networks the pikerd sub-actor brokerd will raise the following upon reconnect to the 2nd net:

tractor._exceptions.RemoteActorError: remote task raised a 'RuntimeError'
   |_src_uid=('brokerd.kraken', '761027ed-ee71-4cea-912d-0777eb74a181')
   |_cid='1e1700a3-f580-4159-9553-1a4b2d05efc5'
   |_boxed_type=<class 'RuntimeError'>
   |
    ------ - ------
    Traceback (most recent call last):
      File "/home/goodboy/repos/tractor/tractor/_rpc.py", line 273, in _errors_relayed_via_ipc
        yield  # run RPC invoke body
        ^^^^^
      File "/home/goodboy/repos/tractor/tractor/_rpc.py", line 642, in _invoke
        res: Any|PayloadT = await coro
                            ^^^^^^^^^^
      File "/home/goodboy/repos/piker/piker/brokers/kraken/broker.py", line 591, in open_trade_dialog
        open_autorecon_ws(
      File "/usr/lib/python3.12/contextlib.py", line 231, in __aexit__
        await self.gen.athrow(value)
      File "/home/goodboy/repos/piker/piker/data/_web_bs.py", line 335, in open_autorecon_ws
        async with trio.open_nursery() as n:
                   ^^^^^^^^^^^^^^^^^^^
      File "/home/goodboy/repos/piker/.venv/lib/python3.12/site-packages/trio/_core/_run.py", line 971, in __aexit__
        raise combined_error_from_nursery
      File "/home/goodboy/repos/piker/piker/data/_web_bs.py", line 265, in _reconnect_forever
        await n.start(
      File "/home/goodboy/repos/piker/.venv/lib/python3.12/site-packages/trio/_core/_run.py", line 1246, in start
        async with open_nursery(strict_exception_groups=False) as old_nursery:
      File "/home/goodboy/repos/piker/.venv/lib/python3.12/site-packages/trio/_core/_run.py", line 971, in __aexit__
        raise combined_error_from_nursery
      File "/home/goodboy/repos/piker/piker/data/_web_bs.py", line 222, in open_fixture
        async with fixture(nobsws) as ret:
                   ^^^^^^^^^^^^^^^
      File "/usr/lib/python3.12/contextlib.py", line 210, in __aenter__
        return await anext(self.gen)
               ^^^^^^^^^^^^^^^^^^^^^
      File "/home/goodboy/repos/piker/piker/brokers/kraken/broker.py", line 356, in subscribe
        raise RuntimeError(
    RuntimeError: ESession:Invalid session

    {'errorMessage': 'ESession:Invalid session',
     'event': 'subscriptionStatus',
     'status': 'error',
     'subscription': {'name': 'openOrders'}}
    ------ - ------
   _|

  ------ - ------
 _|

DESIRED FIX

  • we handle the API error and do a re-connect from within that .kraken.broker.subscribe()’s enter body, INCLUDING a request to get a new ws token, i.e. rerunning the code,
            # Get websocket token for authenticated data stream
            # Assert that a token was actually received.
            resp = await client.endpoint('GetWebSocketsToken', {})
            if err := resp.get('error'):
                raise BrokerError(err)

which currently is sitting @ https://pikers.dev/pikers/piker/src/branch/fix_deribit_hist_queries/piker/brokers/kraken/broker.py#L579

That will implicitly trigger a new .api.Client._private() call beneath and hopefully avoid this stale session issue 🙏

Moving between networks the `pikerd` sub-actor `brokerd` will raise the following upon reconnect to the 2nd net: ```python tractor._exceptions.RemoteActorError: remote task raised a 'RuntimeError' |_src_uid=('brokerd.kraken', '761027ed-ee71-4cea-912d-0777eb74a181') |_cid='1e1700a3-f580-4159-9553-1a4b2d05efc5' |_boxed_type=<class 'RuntimeError'> | ------ - ------ Traceback (most recent call last): File "/home/goodboy/repos/tractor/tractor/_rpc.py", line 273, in _errors_relayed_via_ipc yield # run RPC invoke body ^^^^^ File "/home/goodboy/repos/tractor/tractor/_rpc.py", line 642, in _invoke res: Any|PayloadT = await coro ^^^^^^^^^^ File "/home/goodboy/repos/piker/piker/brokers/kraken/broker.py", line 591, in open_trade_dialog open_autorecon_ws( File "/usr/lib/python3.12/contextlib.py", line 231, in __aexit__ await self.gen.athrow(value) File "/home/goodboy/repos/piker/piker/data/_web_bs.py", line 335, in open_autorecon_ws async with trio.open_nursery() as n: ^^^^^^^^^^^^^^^^^^^ File "/home/goodboy/repos/piker/.venv/lib/python3.12/site-packages/trio/_core/_run.py", line 971, in __aexit__ raise combined_error_from_nursery File "/home/goodboy/repos/piker/piker/data/_web_bs.py", line 265, in _reconnect_forever await n.start( File "/home/goodboy/repos/piker/.venv/lib/python3.12/site-packages/trio/_core/_run.py", line 1246, in start async with open_nursery(strict_exception_groups=False) as old_nursery: File "/home/goodboy/repos/piker/.venv/lib/python3.12/site-packages/trio/_core/_run.py", line 971, in __aexit__ raise combined_error_from_nursery File "/home/goodboy/repos/piker/piker/data/_web_bs.py", line 222, in open_fixture async with fixture(nobsws) as ret: ^^^^^^^^^^^^^^^ File "/usr/lib/python3.12/contextlib.py", line 210, in __aenter__ return await anext(self.gen) ^^^^^^^^^^^^^^^^^^^^^ File "/home/goodboy/repos/piker/piker/brokers/kraken/broker.py", line 356, in subscribe raise RuntimeError( RuntimeError: ESession:Invalid session {'errorMessage': 'ESession:Invalid session', 'event': 'subscriptionStatus', 'status': 'error', 'subscription': {'name': 'openOrders'}} ------ - ------ _| ------ - ------ _| ``` #### DESIRED FIX - we handle the API error and do a re-connect from within that `.kraken.broker.subscribe()`'s enter body, INCLUDING a request to get a new ws token, i.e. rerunning the code, ```python # Get websocket token for authenticated data stream # Assert that a token was actually received. resp = await client.endpoint('GetWebSocketsToken', {}) if err := resp.get('error'): raise BrokerError(err) ``` which currently is sitting @ https://pikers.dev/pikers/piker/src/branch/fix_deribit_hist_queries/piker/brokers/kraken/broker.py#L579 That will implicitly trigger a new `.api.Client._private()` call beneath and hopefully avoid this stale session issue 🙏
Poster
Owner

Also, thinking ahead, we should definitely aim for having at least a small suite of “roaming brokerd/datad” tests for backends that can support it.

More or less this should verify that each backend opting to use our .data._web_bs.NoBsWs provides a correctly implemented fixture that can withstand net dropouts/changes.

Also, thinking ahead, we should definitely aim for having at least a small suite of "roaming `brokerd`/`datad`" tests for backends that can support it. More or less this should verify that each backend opting to use our `.data._web_bs.NoBsWs` provides a correctly implemented `fixture` that can withstand net dropouts/changes.
Sign in to join this conversation.
No Label
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: pikers/piker#14
There is no content yet.