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

fix for stack growth on reconnect #854

Merged
merged 51 commits into from Sep 4, 2022

Conversation

bubbleboy14
Copy link
Collaborator

previously, using the default (synchronous) dispatcher, reconnecting would cause the stack to grow.

here's the fix.

bubbleboy14 and others added 30 commits December 7, 2021 15:44
…d except TimeoutError - raise WebSocketTimeoutException
…ent compatibility): WrappedDispatcher (for use with generic event dispatchers such as pyevent and rel); create_dispatcher() accepts dispatcher kwarg (default None), and if it is specified, returns a WrappedDispatcher; use create_dispatcher() (passing specified dispatcher if any) every time (regardless of dispatcher specification)
…fault False] is True) to setSock() (prevents those lines from running on ConnectionRefusedError)
… mode); added stack frame count to disconnect (warning) log; grossly oversimplified ;)
…er (uses timeout()); setSock() reconnecting (default False) kwarg - if reconnecting, skip handleDisconnect(); handleDisconnect() calls dispatcher.reconnect()
@aantn
Copy link

aantn commented Sep 2, 2022

Does the stack grow in version 1.3.3 as well or only 1.4.0?

@ollo69
Copy link

ollo69 commented Sep 3, 2022

Hi, I don't know about stack grow, but for sure 1.4.0 is introducing a bug when used with SSLDispatcher that is causing error AttributeError: 'SSLDispatcher' object has no attribute 'timeout' during disconnect. This was also fixed in PR #855 that was closed because was containing same code of this PR. I think this should be fixed with priority, doesn't it?

@aantn
Copy link

aantn commented Sep 3, 2022

We've rolled back to version 1.3.3 - the upgrade to version 1.4.0 broke something for us. Our server might be responsible too, but the client behaviour in 1.3.3 didn't cause any trouble.

@@ -6,6 +6,7 @@
import websocket as ws
import ssl
import unittest
import rel
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is to fix the testRunForeverDispatcher() test -- the 'dispatcher="Dispatcher"' previously on line 101 isn't correct.

I'm not sure if lines 102-103 will actually make the test work, I don't know how to add rel to the test dependencies.

Do these tests work in the master branch? As far as I can tell, testRunForeverDispatcher() at least doesn't seem like it could have.

@codecov
Copy link

codecov bot commented Sep 3, 2022

Codecov Report

Merging #854 (b0817c0) into master (6117159) will decrease coverage by 1.66%.
The diff coverage is 67.01%.

@@            Coverage Diff             @@
##           master     #854      +/-   ##
==========================================
- Coverage   84.53%   82.87%   -1.67%     
==========================================
  Files          13       13              
  Lines        1293     1331      +38     
  Branches      274      278       +4     
==========================================
+ Hits         1093     1103      +10     
- Misses        128      153      +25     
- Partials       72       75       +3     
Impacted Files Coverage Δ
websocket/_core.py 80.95% <ø> (-0.96%) ⬇️
websocket/_app.py 75.89% <64.70%> (-9.22%) ⬇️
websocket/_logging.py 82.05% <75.00%> (+0.97%) ⬆️
websocket/_http.py 86.32% <83.33%> (ø)
websocket/__init__.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@bubbleboy14
Copy link
Collaborator Author

Hello all. @engn33r, all the tests are passing now, with the exception of the Codecov tests (which indicate decreased coverage), which makes sense, because there aren't tests yet for the new code.

I disabled the testRunForeverDispatcher() test because it can only work with rel, but I don't know how to add rel to the test dependencies. Also, I don't think this test is working in master.

I propose we merge this in and call it 1.4.1 for @aantn and @ollo69 and the other ha-samsungtv-smart people.

@engn33r
Copy link
Collaborator

engn33r commented Sep 4, 2022

Nice work @bubbleboy14! I will merge and create a new release. With all the effort you've put in lately, send me an email at websocket.client.email [at] gmail.com if you're interested in joining as a co-maintainer.

@engn33r engn33r merged commit 3baacda into websocket-client:master Sep 4, 2022
@maksimu
Copy link

maksimu commented Sep 6, 2022

after upgrading to 1.4.1 i'm getting following error:

++Sent raw: b'\x81\xaa{\xe3\x0c\x01\x00\xc1eeY\xd9,#\x18\x8ccj\x12\x86.-[\xc1|`\x02\x8fc`\x1f\xc16!Y\xa1MS>\xbc^N.\xb7ISY\x9e'
++Sent decoded: fin=1 opcode=1 data=b'{"id": "cok", "payload": "NONE"}'
websocket connected
'socket' object has no attribute 'pending' - goodbye
Warning: Output is not to a terminal (fd=1).

Things work as expected with version 1.3.3

wondering from where this error is coming from?

@maksimu
Copy link

maksimu commented Sep 7, 2022

Actually found that the error is coming from THIS line

@bubbleboy14
Copy link
Collaborator Author

Actually found that the error is coming from THIS line

Funny thread about sock.pending(): https://bugs.python.org/issue21430

These people in 2014 were saying "this function should not be used" - maybe it got removed in a recent version of Python.

Feel up to patching this @maksimu?

@maksimu
Copy link

maksimu commented Sep 7, 2022

Funny thread about sock.pending(): https://bugs.python.org/issue21430

Funny indeed, and puzzling at the same time.

maybe it got removed in a recent version of Python

I doubt, I'm on Python 3.10 and it works fine with websocket-client version 1.3.3 but when I upgrade it to 1.4.0+ I'm getting this error.

Feel up to patching this @maksimu?

Python is not my strongest language, just maintaining things here and there, so I would be better if someone more knowledgeable could look at what's going on and patch it up.

@bubbleboy14
Copy link
Collaborator Author

@maksimu do you have a concise test case for this? My wss tests aren't failing.

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

Successfully merging this pull request may close these issues.

None yet

5 participants