mandrewcito / signalrcore

SignalR Core python client
https://mandrewcito.github.io/signalrcore/
MIT License
119 stars 57 forks source link

Message Received issue when server is hosted in azure #42

Closed javierbarre closed 3 years ago

javierbarre commented 4 years ago

I have a signalr server working locally and the py lib is receiving and executing the "OnConnected" callback OK.

hub_connection.on("OnConnected", onConnected)
def onConnected(result):
    print("onConnected Executed")

But when this same server is hosted in azure (slower connection and https), the OnConnected Callback does not execute in the client.

Here is the socket_trace when server is hosted locally, and with the callback working:

2020-10-13 12:15:13,193 - SignalRCoreClient - DEBUG - -- web socket open --
2020-10-13 12:15:13,203 - SignalRCoreClient - DEBUG - Sending message <signalrcore.messages.handshake.request.HandshakeRequestMessage object at 0x000001E12E7B4F60>
2020-10-13 12:15:13,209 - SignalRCoreClient - DEBUG - {"protocol": "json", "version": 1}
2020-10-13 12:15:13,219 - websocket - DEBUG - send: b'\x81\xa3h!\x03P\x13\x03s"\x07Ul3\x07M!jH\x03i#\x07O!|H\x03u5\x1aRj?\x06\x039pY\\\x1d'
2020-10-13 12:15:13,247 - SignalRCoreClient - DEBUG - Message received{}
2020-10-13 12:15:13,253 - SignalRCoreClient - DEBUG - Evaluating handshake {}
connection opened and handshake received ready to send messages
2020-10-13 12:15:13,282 - SignalRCoreClient - DEBUG - Message received{"type":1,"target":"OnConnected","arguments":["Ff78p4MwJDZlXX5iW-9IdQ","{\r\n  \"FriendlyId\": \"//DESKTOP-Q5VIKIO/ant-ipc-server\",\r\n  \"ComputerName\": \"DESKTOP-Q5VIKIO\",\r\n  \"Version\": \"2.4.5\",\r\n  \"OSPlatformName\": \"Windows\",\r\n  \"OSVersion\": \"Microsoft Windows NT 6.2.9200.0\"\r\n}"]}
2020-10-13 12:15:13,289 - SignalRCoreClient - DEBUG - Raw message incomming: 
2020-10-13 12:15:13,294 - SignalRCoreClient - DEBUG - {"type":1,"target":"OnConnected","arguments":["Ff78p4MwJDZlXX5iW-9IdQ","{\r\n  \"FriendlyId\": \"//DESKTOP-Q5VIKIO/ant-ipc-server\",\r\n  \"ComputerName\": \"DESKTOP-Q5VIKIO\",\r\n  \"Version\": \"2.4.5\",\r\n  \"OSPlatformName\": \"Windows\",\r\n  \"OSVersion\": \"Microsoft Windows NT 6.2.9200.0\"\r\n}"]}
onConnected Executed

Here is the same socket_trace when server is hosted in azure, the trace shows a MessageReceived but the OnConnected is not executing:

2020-10-13 12:15:42,451 - SignalRCoreClient - DEBUG - -- web socket open --
2020-10-13 12:15:42,457 - SignalRCoreClient - DEBUG - Sending message <signalrcore.messages.handshake.request.HandshakeRequestMessage object at 0x000001DFB1B14710>
2020-10-13 12:15:42,468 - SignalRCoreClient - DEBUG - {"protocol": "json", "version": 1}
2020-10-13 12:15:42,474 - websocket - DEBUG - send: b'\x81\xa3\x9f\xf4.\x99\xe4\xd6^\xeb\xf0\x80A\xfa\xf0\x98\x0c\xa3\xbf\xd6D\xea\xf0\x9a\x0c\xb5\xbf\xd6X\xfc\xed\x87G\xf6\xf1\xd6\x14\xb9\xae\x890'
2020-10-13 12:15:42,542 - SignalRCoreClient - DEBUG - Message received{}{"type":1,"target":"OnConnected","arguments":["6klZZBVJu6nArTSofgT04w","{\r\n  \"FriendlyId\": \"//RD281878EF439C/ant-ipc-server\",\r\n  \"ComputerName\": \"RD281878EF439C\",\r\n  \"Versio
n\": \"2.4.5\",\r\n  \"OSPlatformName\": \"Windows\",\r\n  \"OSVersion\": \"Microsoft Windows NT 10.0.14393.0\"\r\n}"]}
2020-10-13 12:15:42,549 - SignalRCoreClient - DEBUG - Evaluating handshake {}{"type":1,"target":"OnConnected","arguments":["6klZZBVJu6nArTSofgT04w","{\r\n  \"FriendlyId\": \"//RD281878EF439C/ant-ipc-server\",\r\n  \"ComputerName\": \"RD281878EF439C\",\r\n  \"V
ersion\": \"2.4.5\",\r\n  \"OSPlatformName\": \"Windows\",\r\n  \"OSVersion\": \"Microsoft Windows NT 10.0.14393.0\"\r\n}"]}
connection opened and handshake received ready to send messages
javierbarre commented 4 years ago

What we found is that in the case that is hosted in azure (and probably because connection speed?) looks like two messages come in one "on_message" execution (see the last socket_trace)

A quick work around for us was to modify base_hub_connection.py

    def on_message(self, raw_message):
        if "{}" in raw_message:
            self.on_message1("{}")
            if len(raw_message) > 2:
                self.on_message1(raw_message.replace("{}", ""))
        else:
            self.on_message1(raw_message)

    def on_message1(self, raw_message):

It worked ok. Let us know a permanent fix

Thanks

stsdc commented 3 years ago

@javierbarre tried Your solution but with no success :(

What is interesting, that it works on desktop, but refuses to handshake on our Jetson device.

javierbarre commented 3 years ago

Do you have the socket_trace out put?

On Thu, Mar 4, 2021 at 12:53 PM Stanisław notifications@github.com wrote:

@javierbarre https://github.com/javierbarre tried Your solution but with no success :(

What is interesting, that it works on desktop, but refuses to handshake on our Jetson device.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/mandrewcito/signalrcore/issues/42#issuecomment-790807883, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABJSCIAPTHNPFU3YDJTXHE3TB7CKBANCNFSM4SPGYUVQ .

-- Javier Barreiro *ANT* Automation 651 Holiday Dr STE 400, Pittsburgh, PA 15220 Ph: +1 412 736 9170 www.ant-automation.com https://www.facebook.com/antautomation/

https://twitter.com/Replic_ANT https://www.youtube.com/channel/UCvDvkF7LUwemQSx9FjiWBJw https://www.linkedin.com/company/ant-automation-applying-new-technologies- [image: aaa] https://www.ant-automation.com

stsdc commented 3 years ago

@javierbarre I tried socket_trace, but didn't find anything useful. What I should look for?

javierbarre commented 3 years ago

It was just asking, to check that if the issue was the same I had. Check if the raw message received is more than one element.

In my case, the issue was that the message received was split into two objects (one of the EMPTY)

Example (as in my second post on this thread)

2020-10-13 12:15:42,542 - SignalRCoreClient - DEBUG - Message received{}{message_with_all_fields_here}

As you can see the raw Message received had two {}{xxx} elements. So I find that the def on_message(self, raw_message): function didn't expect a case like that. Two "elements" in the same raw message.

mandrewcito commented 3 years ago

Hi,

I think that this commits solves your issue,

I will comment here when the new version gets published

Basically, i made a mistake. Handshake´s function only considers an incoming message, not various. I fixed it in the following commit:

https://github.com/mandrewcito/signalrcore/commit/e99dd33089c49229ec2c543256f7b8502cc190e6

thanks, and sorry for the delay!

mandrewcito commented 3 years ago

https://pypi.org/project/signalrcore/0.8.9/

javierbarre commented 3 years ago

That's great!!! Thank you for solving this issue