matrix-org / matrix-python-sdk

Matrix Client-Server SDK for Python 2 and 3
Apache License 2.0
256 stars 119 forks source link

MatrixRequestError 500 after some time when idle #30

Closed vanous closed 8 years ago

vanous commented 8 years ago

i have long running bot made of the matrix python client and in past couple of weeks, it would randomly (often overnight) stop receiving incoming traffic with this error message (sorry, i have screenshot only):

screenshot from 2016-08-03 15-04-07

The error is too deep in threading for me to understand :/ , sorry. Interestingly enough, this started repeatedly about week ago , this last night it didn't happen.... I am reachable @vanous:matrix.org . thank you

erikjohnston commented 8 years ago

Is this against the matrix.org server? If so, what's the user ID of the bot? Looks like there may be a server side bug, given MatrixRequestError: 500, but the SDK should retry on 500's.

vanous commented 8 years ago

yes, matrix HS, by ID i presume you mean username, it is "podoli-server".

erikjohnston commented 8 years ago

Thanks, there don't seem to be any reported errors, so it may just be that we restarted synapse at that time.

So the bug is simply that the SDK needs to retry requests on 5xx responses from the server.

vanous commented 8 years ago

Before my report, i had tried to sandwich some return True around in the listen_forever / start_listener_thread but that didn't help.... but my knowledge is unfortunately limited...

erikjohnston commented 8 years ago

I think @Half-Shot is currently looking at rewriting that bit of code atm, which will probably fix this.

Half-Shot commented 8 years ago

Closing this as I believe it is fixed. Feel free to reopen @vanous if you run into issues again.

vanous commented 8 years ago

huh, i am too late here :) ...thanks for the release, i just returned from short vacation and it seems working.

One comment about the pypi package, might as well put it here, feel free to move some place else:

pip still installs 0.0.3, not sure why...:

pip install -vvv matrix-client Converted retries value: Retry(total=5, connect=None, read=None, redirect=None) -> Retry(total=Retry(total=5, connect=None, read=None, redirect=None), connect=None, read=None, redirect=None) Converted retries value: Retry(total=5, connect=None, read=None, redirect=None) -> Retry(total=Retry(total=5, connect=None, read=None, redirect=None), connect=None, read=None, redirect=None) Collecting matrix-client 1 location(s) to search for versions of matrix-client:

Successfully installed matrix-client-0.0.3 Cleaning up... Converted retries value: Retry(total=0, connect=None, read=None, redirect=None) -> Retry(total=Retry(total=0, connect=None, read=None, redirect=None), connect=None, read=None, redirect=None) Converted retries value: Retry(total=0, connect=None, read=None, redirect=None) -> Retry(total=Retry(total=0, connect=None, read=None, redirect=None), connect=None, read=None, redirect=None)

Half-Shot commented 8 years ago

https://pypi.python.org/pypi/matrix-client/0.0.4 :/ That's...very strange.

EDIT: It does indeed. I'll investigate.

vanous commented 8 years ago

yes. Tried on two computers, erased caches in .cache/pip to no avail... i then installed it correctly via pip install url.

vanous commented 8 years ago

Perhaps this can help... PyPI Release Checklist: https://gist.github.com/audreyr/5990987

vanous commented 8 years ago

still on topic, but probably not an issue, just FYI. I have tested and if i long term heavily over-load my internet connection, i can get connection issues. So here is example how the new sync performs under these conditions. feel free to ignore or let me know if i can be of any help testing it. cheers P.

debug.txt

Half-Shot commented 8 years ago

(Fixed the PyPI issue btw, I did something extremely daft and it's all fine now)

Thanks for the log, Looks like we are still running into issues with the spam. Does the bot continue to work after these errors?

vanous commented 8 years ago

yes, the bot still works, see another debug file. Sometimes i have to submit my command few times before connection is re-established, then it works.

In the log, these lines:

msg received: @vanous !debug msg received: @vanous !address msg received: @vanous !webcam msg received: @vanous !debug msg received: @vanous !debug DEBUG

are my commands to the bot. (I can now change matrix-client logging level during runtime, to have more or less verbosity)

deb.txt

i have again removed token, but kept room id.

Edit: the blocked network is surely caused by buffer bloat. Way to test was to start downloading linux client for WarThunder for the teenager in my house :)

Edit 2: it wouldn't be a bad idea to have timestamp with the log entires.

vanous commented 8 years ago

Btw, still can see the 500 error, this happens during start/login. Few tries and then it works.

Traceback (most recent call last): File "reader.py", line 26, in token=client.login_with_password(my_username,my_password) File "/usr/local/lib/python2.7/dist-packages/matrix_client/client.py", line 134, in login_with_password "m.login.password", user=username, password=password File "/usr/local/lib/python2.7/dist-packages/matrix_client/api.py", line 144, in login return self._send("POST", "/login", content) File "/usr/local/lib/python2.7/dist-packages/matrix_client/api.py", line 400, in _send code=response.status_code, content=response.text matrix_client.api.MatrixRequestError: 500: pi@raspberrypi:~/bin $ pi@raspberrypi:~/bin $ python reader.py Traceback (most recent call last): File "reader.py", line 26, in token=client.login_with_password(my_username,my_password) File "/usr/local/lib/python2.7/dist-packages/matrix_client/client.py", line 134, in login_with_password "m.login.password", user=username, password=password File "/usr/local/lib/python2.7/dist-packages/matrix_client/api.py", line 144, in login return self._send("POST", "/login", content) File "/usr/local/lib/python2.7/dist-packages/matrix_client/api.py", line 400, in _send code=response.status_code, content=response.text matrix_client.api.MatrixRequestError: 500: pi@raspberrypi:~/bin $ python reader.py Traceback (most recent call last): File "reader.py", line 26, in token=client.login_with_password(my_username,my_password) File "/usr/local/lib/python2.7/dist-packages/matrix_client/client.py", line 134, in login_with_password "m.login.password", user=username, password=password File "/usr/local/lib/python2.7/dist-packages/matrix_client/api.py", line 144, in login return self._send("POST", "/login", content) File "/usr/local/lib/python2.7/dist-packages/matrix_client/api.py", line 400, in _send code=response.status_code, content=response.text matrix_client.api.MatrixRequestError: 500:

Half-Shot commented 8 years ago

500s are odd. That's usually a server problem :/