LUCIT-Systems-and-Development / unicorn-binance-websocket-api

A Python SDK by LUCIT to use the Binance Websocket API`s (com+testnet, com-margin+testnet, com-isolated_margin+testnet, com-futures+testnet, com-coin_futures, us, tr, dex/chain+testnet) in a simple, fast, flexible, robust and fully-featured way.
https://unicorn-binance-websocket-api.docs.lucit.tech/
Other
683 stars 164 forks source link

Websocket not able to reconnect #27

Closed GezaBoi closed 5 years ago

GezaBoi commented 5 years ago

Check this or we will delete your issue. (fill in the checkbox with an X like so: [x])

Select one:

Environment

Operating System? (include version)

Python Version Requirement

Exact Python Version?

Include here the response of 'python --version' or 'python3 --version'

Python 3.6.0

Pip Version?

Include here the response of 'pip --version' or 'pip3 --version'

pip 10.0.1

Dependencies

Run pip list > pip_list.txt and upload the file. pip_list.txt

UNICORN Binance WebSocket API Version?

Did you upgrade to the latest release version with `pip install unicorn-binance-websocket-api --upgrade`?
yes
Please control what version you are using with this script and post the output: https://github.com/unicorn-data-analysis/unicorn-binance-websocket-api/blob/master/tools/get_used_module_version.py

1.6.3

Description of your issue

Today in the Morning at 2019-07-31 05:48:55,454 the Websocket got the last message from Binance. Then the Stream crashed and was not able to reconnect. Only a restart later solved the problem. Relevant logs:

2019-07-31 05:49:02,186 asyncio     : ERROR    Future exception was never retrieved
future: <Future finished exception=ConnectionClosed('WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason',)>
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason
2019-07-31 05:49:02,187 root        : CRITICAL BinanceWebSocketApiSocket->start_socket(b24371ce-a06b-4aca-b1cd-c5f7540b328e, arr, !userData) Exception ConnectionClosed Info: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason

2019-07-31 05:49:04,031 root        : ERROR    BinanceWebSocketApiConnection->await._conn.__aenter__(b24371ce-a06b-4aca-b1cd-c5f7540b328e, arr, ['!userData']) - OSError - [Errno 8] nodename nor servname provided, or not known

2019-07-31 05:49:08,045 root        : ERROR    BinanceWebSocketApiConnection->await._conn.__aenter__(b24371ce-a06b-4aca-b1cd-c5f7540b328e, arr, ['!userData']) - OSError - [Errno 8] nodename nor servname provided, or not known

future: <Future finished exception=ConnectionClosed('WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason',)>
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason
2019-07-31 05:49:08,485 root        : CRITICAL BinanceWebSocketApiSocket->start_socket(09f0fdf2-97ba-47d7-a587-528b0ff6514f, {'depth5', 'kline_1m'}, {'btcusdt', 'bnbusdt'}) Exception ConnectionClosed Info: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason
2019-07-31 05:49:08,485 root        : CRITICAL BinanceWebSocketApiManager->stream_is_crashing(09f0fdf2-97ba-47d7-a587-528b0ff6514f)
2019-07-31 05:49:08,761 root        : ERROR    BinanceWebSocketApiConnection->await._conn.__aenter__(09f0fdf2-97ba-47d7-a587-528b0ff6514f, {'depth5', 'kline_1m'}, {'btcusdt', 'bnbusdt'}) - OSError - [Errno 8] nodename nor servname provided, or not known

then multiple times these two error logs:
2019-07-31 05:49:13,079 root        : ERROR    BinanceWebSocketApiConnection->await._conn.__aenter__(b24371ce-a06b-4aca-b1cd-c5f7540b328e, arr, ['!userData']) - OSError - [Errno 8] nodename nor servname provided, or not known

2019-07-31 05:49:13,794 root        : ERROR    BinanceWebSocketApiConnection->await._conn.__aenter__(09f0fdf2-97ba-47d7-a587-528b0ff6514f, {'depth5', 'kline_1m'}, {'btcusdt', 'bnbusdt'}) - OSError - [Errno 8] nodename nor servname provided, or not known

and then it ends with this log:
2019-07-31 05:50:16,516 asyncio     : ERROR    Task was destroyed but it is pending!
task: <Task pending coro=<WebSocketCommonProtocol.close_connection() done, defined at *path*/venv/lib/python3.6/site-packages/websockets/protocol.py:1002> wait_for=<Future pending cb=[<TaskWakeupMethWrapper object at 0x11ecedaf8>()]>>
oliver-zehentleitner commented 5 years ago

Hello!

What was necessary to restart? Your app or macOS?

The error message "OSError - [Errno 8] nodename nor servname provided, or not known" indicates that your system was not able to resolve the address of binance websocket endpoints.

if it happens again, try to reset the DNS cache, set down the TTL or disable the DNS cache: https://coolestguidesontheplanet.com/clear-the-local-dns-cache-in-osx/

Best regards, Oliver

GezaBoi commented 5 years ago

I just restarted my app. That fixed it. It is also running since then without any problem, but I will get back to you if it crashes again.

In the end I want to run the app on a linux server. Do you think the bug is caused by macOS?

oliver-zehentleitner commented 5 years ago

i run this lib on servers and i have just one reconnect in about 2 weeks per stream. The most interruptions are caused by the internet connection it self.

The reason why the lib cant reconnect to the binance endpoints is: OSError - [Errno 8] nodename nor servname provided, or not known

And thats a task and message of the operating system...

I am also testing with macOS but only the latest version and not in a datacenter: Bildschirmfoto 2019-08-02 um 11 48 01