Coder Social home page Coder Social logo

Comments (10)

bubbleboy14 avatar bubbleboy14 commented on June 8, 2024 1

@gborrageiro-ld @andrea-mucci @engn33r

I put together a websocket throughput test in dez, which is an async network stack built on rel. The new test is in the latest version, 0.10.10.1, which can be installed thusly:

pip install dez

To run the test, first run this:

dez_test wsecho

That starts up a pretty basic websocket echo server (code) with a couple extra features.

Then, in a different terminal, run:

dez_test wsc

That (code) will prompt you to select a test configuration (high throughput in upstream/downstream/both/neither directions). It will then start up a WebSocketApp (with rel dispatcher) and proceed to direct heavy traffic in the specified direction. Anyway, it runs fine for me in every configuration.

Is anyone able to reproduce the issue using this test? Feel free to modify the code. Or is there a different websocket server that has this issue? For whatever reason, it doesn't seem to be a problem with dez.

Anyway, this shouldn't be hard to fix, if anyone can come up with a reliable repro - thoughts and test cases welcome!

from websocket-client.

bubbleboy14 avatar bubbleboy14 commented on June 8, 2024

@gborrageiro-ld thanks for the detailed report! Do you get the same SSLEOFError with the default (unspecified) dispatcher - that is, connected to the same endpoint, but without rel?

Also, since it looks like it's throwing this error in the course of trying to send a pong, I'm wondering whether the same problem is still encountered if you don't specify ping_interval and ping_timeout.

from websocket-client.

gborrageiro-ld avatar gborrageiro-ld commented on June 8, 2024

hi @bubbleboy14,

I have two streams, one authenticated and the other is unauthenticated. I depend on a dispatcher like rel to handle multiple streams; what alternatives would you suggest?
If I remove the ping/pong, then the exception does eventually occur, yes.

Thanks
Gabriel

from websocket-client.

gborrageiro-ld avatar gborrageiro-ld commented on June 8, 2024

I removed rel and let the busy, unauthenticated stream run, and I do not see this segmentation fault.

from websocket-client.

bubbleboy14 avatar bubbleboy14 commented on June 8, 2024

Hey @gborrageiro-ld I created a standalone test from the example code you provided:

import rel, websocket

BASEURL = "wss://fstream.binance.com/stream?streams=btcusdt@bookTicker/btcusdt@depth20@100ms/btcusdt@aggTrade/btcusdt@markPrice@1s/btcusdt@"
variants = ["bookTicker", "forceOrder"]

def onmsg(ws, msg):
    print("received:", msg)

for v in variants:
    ws = websocket.WebSocketApp(BASEURL + v, on_message=onmsg)
    ws.run_forever(dispatcher=rel, reconnect=3, ping_interval=180, ping_timeout=60)

rel.dispatch()

I've been running it for a while, and I haven't gotten that SSLEOFError. Does it take a long time? Are you able to reproduce the issue with this test case? If not, could you modify it to produce the error?

Anyway, thanks a million for the excellent report, we should be able to track this one down. LMK how it goes!

from websocket-client.

andrea-mucci avatar andrea-mucci commented on June 8, 2024

Hi,

I have the same error but with a different approach

i have a client that only send data to a server

.....
self.socket = websocket.WebSocket()
self.socket.connect(self.url)

#this is the method that send a command
def command(content):
     self.socket.send(....)

nothing special, the problem is that if i start to send messages from a loop, like:

for item in items:
     __method_that_send_ws_message()

in a certin point a get a failure:

  File "/home/andrea/PycharmProjects/ArchAI/archai/venv/lib/python3.10/site-packages/websocket/_core.py", line 283, in send
    return self.send_frame(frame)
  File "/home/andrea/PycharmProjects/ArchAI/archai/venv/lib/python3.10/site-packages/websocket/_core.py", line 311, in send_frame
    l = self._send(data)
  File "/home/andrea/PycharmProjects/ArchAI/archai/venv/lib/python3.10/site-packages/websocket/_core.py", line 525, in _send
    return send(self.sock, data)
  File "/home/andrea/PycharmProjects/ArchAI/archai/venv/lib/python3.10/site-packages/websocket/_socket.py", line 170, in send
    return _send()
  File "/home/andrea/PycharmProjects/ArchAI/archai/venv/lib/python3.10/site-packages/websocket/_socket.py", line 147, in _send
    return sock.send(data)
  File "/usr/lib/python3.10/ssl.py", line 1206, in send
    return self._sslobj.write(data)
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:2426)

the strange thing is that before the error i have already sent a lot of messages, the problem come if a send the messages from a loop in a method

from websocket-client.

bubbleboy14 avatar bubbleboy14 commented on June 8, 2024

@andrea-mucci hm, interesting. the python ssl docs say:

A subclass of SSLError raised when the SSL connection has been terminated abruptly. Generally, you shouldn’t try to reuse the underlying transport when this error is encountered.

i don't know enough about the inner workings (of python's ssl module) to say how wide an array of circumstances (beyond a simple connection drop) can lead to this.

however, since you and @gborrageiro-ld both describe high throughput situations, i wonder whether, perhaps, some buffer is filling up... i mean, it really shouldn't be something like that. do you have any thoughts on this, @engn33r ?

i notice you're both running py3.10 - this may be related.

@andrea-mucci are you using the rel dispatcher?

can anyone provide a concise repro?

from websocket-client.

engn33r avatar engn33r commented on June 8, 2024

Checking any search engine for "python EOF occurred in violation of protocol" shows this a common error message and often related to the SSL library. I suggest sharing the OS that you are using (Windows, Mac, *nix) and the output of these commands when such an SSL error is encountered:

openssl version
python3 -c "import ssl; print(ssl.OPENSSL_VERSION); import websocket; print(websocket.__version__)"
python3 -V

from websocket-client.

gborrageiro-ld avatar gborrageiro-ld commented on June 8, 2024

from websocket-client.

bubbleboy14 avatar bubbleboy14 commented on June 8, 2024

@engn33r @gborrageiro-ld @andrea-mucci

I just encountered this issue myself! This patch fixed it for me:

#961

Does it fix things for you guys?

It's just two small changes in read() (in run_forever()): 1) check for SSLEOFError; 2) pass bool(reconnect) to handleDisconnect().

@engn33r, these seem like logical tweaks, right? Fixes the issue for me, anyway.

LMK what you think!

from websocket-client.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.