crossbario / autobahn-python

WebSocket and WAMP in Python for Twisted and asyncio
https://crossbar.io/autobahn
MIT License
2.47k stars 763 forks source link

connection lost while called for Twisted, bug-like issue #1621

Closed Pborz closed 1 year ago

Pborz commented 1 year ago

code structure: reactor.callFromThread(self.addConnection, channel)

def addConnection(self, channel):
        self.conns[channel] = connectWS(self.factories[channel])

1) reactor is from twisted.internet import reactor

2) self.factories[channel] is from

(WsClientFactory)
    def __init__(self, *args, payload=None, **kwargs):
        WebSocketClientFactory.__init__(self, *args, **kwargs)

3) self.factories[channel]
web sockets url: wss://ws.okx.com:8443/ws/v5/public?brokerId=9999 arg payload:

payload = json.dumps({"op": "subscribe", "args": "{'channel': 'books', 'instId': 'BTC-USDT-SWAP'}}", ensure_ascii=False).encode(
            "utf8")

4) when connectWS to above params, we got:

WsClientFactory execute clientConnectionLost. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
],retried 1 times
WsClientFactory execute clientConnectionLost. Reason: [Failure instance: Traceback (failure with no frames): <class 'twisted.internet.error.ConnectionDone'>: Connection was closed cleanly.
],retried 2 times

it is sure that normal ws connect to that url is ok, and the issue is caused at exactly reactor.callFromThread(self.addConnection, channel) so maybe the connectWS in the self.addConnection has bug-like issue, THX !!!!

Pborz commented 1 year ago

@oberstet

Pborz commented 1 year ago

@Roms1383

Pborz commented 1 year ago

this project has been abandoned? same bug issue several years ago no contributor cares and now again??

om26er commented 1 year ago

Pretty sure the project hasn't been abandoned but you could perhaps do a PR to fix the issue if that bothers you

Pborz commented 1 year ago

OH seriously uhhh so anyone who come out and solve this bro issue? #1267 why so obvious bug-like issue WAS ABANDONED several YEARS ago huh 🤔😑 @om26er if anyone not, that’s the real botherrrrrrrr

oberstet commented 1 year ago

Hi there,

@om26er is perfectly right. this project isn't abandoned, it is used in production in various systems.

@Pborz when you say "why so obvious bug-like issue WAS ABANDONED several YEARS ago huh": there is no bug in autobahn. if you think otherwise, provide a complete test case or example, or a PR together with test cases.

connectWS is an ancient API using ancient Twisted APIs, and you can't call that from a background thread via callFromThread.

The modern API for establishing WebSocket client connections is using Twisted Endpoints, here is a screenshot from a project in crypto which connects to various exchange feeds ... connect_exchange_feed can be called from background threads (via callFromThread)

grafik

Pborz commented 1 year ago

ok huh so first, why that bro #1267 didn’t get whatever like this? no even single character. answering whatever like this now, isn’t that goodness? if I say that ‘ it’s my idea to turn you guys all on that an interesting way —cry out ridiculous words—to activate everyone to discuss and solve something, wouldn’t that be so tragically? second, connectWS is ancient balabala, so if it is a newbie, how to let them know effectively? by repeating some rules like read doc balabala? third, I not yet read in detail but, why autohabn need to make out a so called ——connect_exchange_feed can be called from background threads (via callFromThread)—— for crypto WS? isn’t that crypto WS not good WS? do you remember that, if someone use the original import websockets to connect() and send(), everything is so smoothly! WHY we need to spending time in something ancient or not? why not based stablely like websockets and every project so easily?

Roms1383 commented 1 year ago

sorry I can't be of any use here, to be honest my issue dates back over 3 years ago and I completely forgot about its details.