Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to limit node reconnect attempts? #37

Closed
grctest opened this issue Jan 22, 2018 · 3 comments
Closed

How to limit node reconnect attempts? #37

grctest opened this issue Jan 22, 2018 · 3 comments

Comments

@grctest
Copy link
Contributor

grctest commented Jan 22, 2018

I'm trying to provide redundent node connections when publishing price feeds for long periods of time.

When I try the following it gets stuck in a reconnect loop for the fist invalid server. Is there a way of providing a timeout of a max connect attempts, so that I can loop through a list of API servers?

full_node_list = ["wss://bitshfares.openledger.info/ws",
                         "wss://bitshares.crypto.fans/ws",
                         "wss://openledger.hk/ws"]

for server in full_node_list:
  try:
    bitshares_api_node = BitShares(server)
    break
  except:
    print(server + " is offline!")

Output:

Lost connection to node during wsconnect(): wss://nodfe.bitshares.eu/ws (2/-1) Retrying in 2 seconds
Lost connection to node during wsconnect(): wss://nodfe.bitshares.eu/ws (3/-1) Retrying in 4 seconds
Lost connection to node during wsconnect(): wss://nodfe.bitshares.eu/ws (4/-1) Retrying in 6 seconds
......

Should I instead try to connect using a 3rd party websocket client to ping the API servers before moving ahead with creating a Bitshares instance?

Cheers

@grctest grctest changed the title How to create redundent full api nodes? How to limit node reconnect attempts? Jan 22, 2018
@grctest
Copy link
Contributor Author

grctest commented Jan 22, 2018

I threw together a chunk of Python code that checks the status of full node API servers prior to attempting any python-bitshares Bitshares() fullnode connections using Lomond:

import wsaccel
from lomond.websocket import WebSocket

if __name__ == "__main__":

    full_node_list = ["wss://node.bitdashares.eu/ws",
                      "wss://dexnfffode.net/ws",
                      "wss://bitshares.openledger.info/ws",
                      "wss://bitshares.crypto.fans/ws",
                      "wss://openledger.hk/ws"]

    online_server = ""
    
    for server in full_node_list:
      if (online_server == ""):
          try:
            ws = WebSocket(server)
            for event in ws.connect():
                print(event.name)
                if event.name == "connect_fail":
                    print(server + " is offline!")
                    break
                if event.name == "connecting":
                    continue
                if event.name == "connected":
                    continue
                if event.name == "ready":
                    online_server = server
                    print(server + " is online!")
                    ws.close()
                    break
          except:
            print(server + " is offline!")

    print("The online server is: {}".format(online_server))

Some error handling or max limit on wsconnect() attempts would still be a great redundancy step, perhaps a node could go down during script execution after having successfully checked it using the above script?

@grctest
Copy link
Contributor Author

grctest commented Feb 3, 2018

Ran into the wsconnect retry loop after pre-checking the API node was up, need an additional/alternative solution..

@xeroc
Copy link
Member

xeroc commented Feb 14, 2018

BitShares() consumes a list of nodes too and cycles thru them

    full_node_list = ["wss://node.bitdashares.eu/ws",
                      "wss://dexnfffode.net/ws",
                      "wss://bitshares.openledger.info/ws",
                      "wss://bitshares.crypto.fans/ws",
                      "wss://openledger.hk/ws"]

    bts = BitShares(full_node_list)

@xeroc xeroc closed this as completed Feb 14, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants