-
Notifications
You must be signed in to change notification settings - Fork 38
huge memory leak right after reconnect #61
Comments
Error ws = MySocket(url='https://socket.bittrex.com/signalr') Just make sure you have installed cfscrape and node.js. The reconnection memory leak is due to the fact that the client tries to reconnect and since it's denied immediately it goes into an infinite loop which causes high CPU usage. This is on my side and I will implement a fix. I am thinking of maximum connection retries solution. |
cpu usage not high at all, but memory usage rising quite fast. |
Doesn't change the fact. Also when posting make sure you specify what Python version you are using and also provide the code you are executing. In this case you said you are using the example but you are also invoking |
Python 2.7.x
|
I will test it now. 1.) How often does the issue happens? 2.) Is there any pattern in the average time between starting the code and the occurrence of the error? E.g every 10mins or so. |
No, it happens just after network error. Sometimes its 2h, sometimes 6-8h |
I see, I will work on a fix and will push it to github in due time. |
Its a temporary fix but do the following: update to the latest version from github and replace line 140-143: elif invoke == BittrexMethods.GET_AUTH_CONTENT:
self.connection.corehub.server.invoke(invoke, payload[0])
self.invokes.append({'invoke': invoke, 'ticker': payload[0]})
logger.info('Retrieving authentication challenge.') with elif invoke == BittrexMethods.GET_AUTH_CONTENT:
self.connection.corehub.server.invoke(invoke, self.credentials['api_key'])
self.invokes.append({'invoke': invoke, 'ticker': self.credentials['api_key']})
logger.info('Retrieving authentication challenge.') |
Also, I notice that you have in the websocket_client.py put a variable 'self.threads = []', but when a thread dies or is finished it is not removed from this list, preventing it from being garbage collected (as there are still references to it) |
Hi, Is node.js installed together with cfscrape? |
Update the package to Theoretically this should fix it, waiting for your feedback after testing. |
As I said I can’t comment on pictures without any code. v1.0.4 is different than the code I posted, you can check the commits. |
As I said, I subscribe and then stick to a function with a I'll test |
As requested, here is a pastebin with full code, is pretty basic honestly.. https://pastebin.com/a5UvBZqU Python version was 3.5, don't believe node.js is installed no. Cfscrape is installed. |
Hi, I will take a look at your logs. Have you updated to v1.0.4. If not, please do so and test.
Cfscrape requires nodejs to work. It’s not resulted in an error on your side so far because bittrex has disabled cloudflare currently. I recommend installing node.js.
…
On May 13, 2018 at 6:42 pm, <ayy1337 ***@***.***)> wrote:
As requested, here is a pastebin with full code, is pretty basic honestly.. https://pastebin.com/a5UvBZqU
And here is a pastebin with the full output from running the above code: https://pastebin.com/LSN9QDMc
Python version was 3.5, don't believe node.js is installed no. Cfscrape is however.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub (#61 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AbVUGwXHjL00m2il0eHFh8M3Stq6KObjks5tyFRvgaJpZM4T0GNn).
|
Okay so I updated and ran the same script again with the new version, have the output from my tests. For the second test I let it run until it ran into an issue on its own, https://pastebin.com/F9y0hLhm In neither case did it successfully reconnect after the error |
Hi, the reason for the error is that exceptions in Python2 have a
@ayy1337 I have added As a whole, I have disabled the auto-reconnection for unknown errors since I prefer to add them when they appear and after I've become acquainted with them. |
Hi @ayy1337, thanks for the suggestion. Also my bad, I pushed directly to the master so you can update through: |
Can you paste the contents of websocket_client.py/_handle_subscribe method? |
I wasn't sure which package was raising the TimeoutError. Initially I thought it was |
Were you getting any data between 00:20 and 12:20? |
Hmm I didn't notice that actually.. appears to be a gap, possibly it didn't succeed in subscribing to summarylitedeltas? |
Yes, that's what I am investigating currently. It seems |
I've made some changes to ensure
|
Okay, will rerun the test (natural reconnect) with the new version |
TimeoutError absent in python 2.x, its not built-in.
|
Will check and push it.
…
On May 21, 2018 at 8:45 pm, <gzivdo ***@***.***)> wrote:
TimeoutError absent in python 2.x, its not built in
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub (#61 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AbVUG0AYHUe6-__dit1fW2ucj0tCEpsVks5t0v0ggaJpZM4T0GNn).
|
Did you get any errors? If so, post the log so that I can check what exception is being raised instead.
…
On May 21, 2018 at 9:27 pm, <Stanislav Lazarov ***@***.***)> wrote:
Will check and push it.
>
> On May 21, 2018 at 8:45 pm, <gzivdo ***@***.***)> wrote:
>
>
>
>
> TimeoutError absent in python 2.x, its not built in
>
>
>
> —
> You are receiving this because you commented.
> Reply to this email directly, view it on GitHub (#61 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AbVUG0AYHUe6-__dit1fW2ucj0tCEpsVks5t0v0ggaJpZM4T0GNn).
>
>
>
|
And then if i comment timeouterror code i get:
And nothing happening after. |
Still no fix? With py2.x just not work at all now. |
I’ve been away for the past 2 weeks, will look into it in the weekend. |
Do a: It should fix the TimeoutError. Regarding: Are you sure that this is not part of your code? Can you repost again your code. |
yes, sorry. |
The error bacause beta api returns with QueryExchangeState 'M' not None, but https://socket.bittrex.com/signalr returns None. Will use beta for now. |
Bittrex hasn’t fixed it in the production socket. I have added a workaround for that, inspect the payload and you would see the ticker name.
…
On Jun 2, 2018 at 10:56 am, <gzivdo ***@***.***)> wrote:
The error bacause beta api returns with QueryExchangeState 'M' not None, but https://socket.bittrex.com/signalr returns None.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub (#61 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AbVUG_kHIMSwZjOfcHnLY7xY-l-NAZTLks5t4kU6gaJpZM4T0GNn).
|
What if i will subscribe for few tickers, how your workaround will handle that? |
First of all, QueryExchangeState is an invoke so for each invoke you would get a new message. Secondly the code is matching the input invoke number with the output number from the signalr connection so it should be ok. However, since it’s not a bittrex official feature but a workaround, I suggest to test it prior to any trading.
…
On Jun 2, 2018 at 11:18 am, <gzivdo ***@***.***)> wrote:
What if i will subscribe for few tickers, how your workaround will handle that?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub (#61 (comment)), or mute the thread (https://github.com/notifications/unsubscribe-auth/AbVUG8x0La8_sDBGSlMHB-l0Iy4lmp87ks5t4ko6gaJpZM4T0GNn).
|
Now after connection dropped i have:
And the app not react on ctrl+c |
Is it stuck on reconnection or what? Seems like you are unable to reconnect at all. |
Dont know, but there was no data after that last message and I cant stop it by ctrl+c |
You are also connecting to the beta endpoint, I can’t guarantee that it is stable. |
I know, but the bug still in the lib. It still cant reconnect and even cant stop the app after retry. |
Is this the full log? Anything after? Firstly, if the library is unable to reconnect after a drop it will keep on trying every 10 seconds. E.g here is an example of when I have disabled my connection and then reenabled it:
Secondly , in your initial code you are handling Thirdly, as I mentioned, don't use the beta endpoint. Finally, the last time you posted your script was 28 days, I guess it has changed by now. Even though, I am trying to help you, I have no idea and I can't guess what you are executing. I need to be able to replicate your issue precisely. |
Yes i am handle Keyboardinterrupt:
Will try to run for a while original 'test' code. Possibly the reason in that i use python 2.7. |
@gzivdo here is an infinite loop test code: #!/usr/bin/python
# -*- coding: utf-8 -*-
from __future__ import print_function
from time import sleep
from bittrex_websocket import BittrexSocket, BittrexMethods
def main():
class MySocket(BittrexSocket):
def on_public(self, msg):
# Create entry for the ticker in the trade_history dict
if msg['invoke_type'] == BittrexMethods.SUBSCRIBE_TO_EXCHANGE_DELTAS:
if msg['M'] not in trade_history:
trade_history[msg['M']] = []
# Add history nounce
trade_history[msg['M']].append(msg)
# Ping
print('[Trades]: {}'.format(msg['M']))
# Create container
trade_history = {}
# Create the socket instance
ws = MySocket()
# Enable logging
ws.enable_log()
# Define tickers
tickers = ['BTC-ETH', 'BTC-NEO', 'BTC-ZEC', 'ETH-NEO', 'ETH-ZEC']
# Subscribe to trade fills
ws.subscribe_to_exchange_deltas(tickers)
ws.subscribe_to_summary_lite_deltas()
ws.authenticate('test your api key', 'test your api secret')
while True:
sleep(1)
if __name__ == "__main__":
main() |
Still having the issue? |
The code just like in example
only with subscribe_to_exchange_deltas
Output
After first reconnect app starts to eat all available memory and swap.
The text was updated successfully, but these errors were encountered: