Nowin icon indicating copy to clipboard operation
Nowin copied to clipboard

websockets timeout with signalr

Open ronnieoverby opened this issue 9 years ago • 7 comments

When switching my app from Microsoft.Owin.Host.HttpListener to Nowin my signalr hub connections via websockets timeout and then succeed when switching to SSE.

Any idea why this is happening?

Everything else seems to work great with the switch to Nowin.

Here's the js client log showing the timeout:

[11:19:46 GMT-0500 (Eastern Standard Time)] SignalR: Negotiating with '/signalr/negotiate?clientProtocol=1.4&connectionData=%5B%7B%22name%22%3A%22eclhub%22%7D%5D'.
jquery.signalR.js:81 [11:19:46 GMT-0500 (Eastern Standard Time)] SignalR: Connecting to websocket endpoint 'ws://localhost:64423/signalr/connect?transport=webSockets&clientProtocol=1.4&connectionToken=AQAAANCMnd8BFdERjHoAwE%2FCl%2BsBAAAA3sJBIyVT%2F0m1h7OYIkqKfgAAAAACAAAAAAADZgAAwAAAABAAAAAdukww50k5%2FeCpx8dHi9pUAAAAAASAAACgAAAAEAAAAI5n9S92vwXqZCl5mr9aOaAwAAAA8%2Fo8SguGi4gUcwOYkGmUJj9T4RhUwQ1%2FGBP4fkW2QF%2FX3C44ZRjBStRxwEX2vX%2BQFAAAAGeplDn%2FBZDlgPoSMU5khj2yuSrc&connectionData=%5B%7B%22name%22%3A%22eclhub%22%7D%5D&tid=9'.
jquery.signalR.js:81 [11:19:46 GMT-0500 (Eastern Standard Time)] SignalR: Websocket opened.
jquery.signalR.js:81 [11:19:51 GMT-0500 (Eastern Standard Time)] SignalR: webSockets timed out when trying to connect.
jquery.signalR.js:81 [11:19:51 GMT-0500 (Eastern Standard Time)] SignalR: Closing the Websocket.
jquery.signalR.js:81 [11:19:51 GMT-0500 (Eastern Standard Time)] SignalR: Attempting to connect to SSE endpoint 'http://localhost:64423/signalr/connect?transport=serverSentEvents&clientPro…PoSMU5khj2yuSrc&connectionData=%5B%7B%22name%22%3A%22eclhub%22%7D%5D&tid=3'.
jquery.signalR.js:81 [11:19:51 GMT-0500 (Eastern Standard Time)] SignalR: EventSource connected.
jquery.signalR.js:81 [11:19:51 GMT-0500 (Eastern Standard Time)] SignalR: serverSentEvents transport selected. Initiating start request.
jquery.signalR.js:81 [11:19:51 GMT-0500 (Eastern Standard Time)] SignalR: The start request succeeded. Transitioning to the connected state.
jquery.signalR.js:81 [11:19:51 GMT-0500 (Eastern Standard Time)] SignalR: Now monitoring keep alive with a warning timeout of 13333.333333333332 and a connection lost timeout of 20000.
jquery.signalR.js:81 [11:19:51 GMT-0500 (Eastern Standard Time)] SignalR: Invoking eclhub.getEcls

ronnieoverby avatar Feb 26 '16 16:02 ronnieoverby

Actually it does not work for SignalR version I have in repository too ... it throws:

---> (Inner Exception #0) System.NotImplementedException: Metoda nebo operace není implementována. v Microsoft.AspNet.SignalR.Owin.OwinWebSocketHandler.OwinWebSocket.get_State() v Microsoft.AspNet.SignalR.WebSockets.WebSocketHandler.SendAsync(ArraySegment1 message, WebSocketMessageType messageType, Boolean endOfMessage) v Microsoft.AspNet.SignalR.WebSockets.DefaultWebSocketHandler.SendChunk(ArraySegment1 message) v Microsoft.AspNet.SignalR.Infrastructure.BinaryTextWriter.<.ctor>b__6(ArraySegment`1 data, Object state)

Could you try to add this into App.config:

<system.diagnostics>

<trace autoflush="true" indentsize="0">
  <listeners>
    <add name="Global"
         type="System.Diagnostics.TextWriterTraceListener"
         initializeData="Global.log">
    </add>
  </listeners>
</trace>

<sources>
  <source name="Nowin.Core">
    <listeners>
      <remove name="Default"/>
      <add name="Nowin.Core" />
    </listeners>
  </source>
  <source name="Nowin.Core.Debug">
    <listeners>
      <remove name="Default"/>
      <add name="Nowin.Core" />
    </listeners>
  </source>
</sources>

<switches>
  <add name="Nowin.Core" value="Verbose" />
  <add name="Nowin.Core.Debug" value="Verbose" />
</switches>

<sharedListeners>
  <add name="Nowin.Core"
       type="System.Diagnostics.TextWriterTraceListener"
       initializeData="Nowin.Core.log" />
</sharedListeners>

</system.diagnostics>

Then look into global.log for exceptions ...

Also what version of SignalR you using?

I also tried simple websocket echo sample and it works without problem... So I suspect something in SignalR ...

Bobris avatar Feb 27 '16 15:02 Bobris

I forgot about this bug https://github.com/SignalR/SignalR/issues/2720 - and it is still open ... So last signalr which worked ok is 1.x version.

Bobris avatar Feb 27 '16 21:02 Bobris

Server side (nuget package):

Client side (bower package):

"signalr": "^2.2.0"

I'll try your suggested config on Monday. Thanks.

ronnieoverby avatar Feb 28 '16 12:02 ronnieoverby

So looking at that ticket you referenced it doesn't seem there is going to be a fix unless I make it myself?

ronnieoverby avatar Feb 28 '16 13:02 ronnieoverby

Looks like it ... I think they will support only .Net core in future, and even SignalR will not be finished for 1.0 version. Now I expect that I will also port Nowin to .Net core after it will at least a little bit stabilize. But it will take atleast 3 months how I see it. Though getState method does not look too difficult to implement so brace yourself and go for it :-)

Bobris avatar Feb 28 '16 13:02 Bobris

For the exception: ---> (Inner Exception #0) System.NotImplementedException: Metoda nebo operace není implementována. v Microsoft.AspNet.SignalR.Owin.OwinWebSocketHandler.OwinWebSocket.get_State()

As a dirty work-around I have added my own OwinWebSocketContext to then environment (see: https://github.com/SignalR/SignalR/blob/master/src/Microsoft.AspNet.SignalR.Core/Owin/OwinWebSocketHandler.cs#L66) The OwinWebSocketContext implements single property "WebSocket" (others throw NotImplementedException) that returns my custom implementation of OwinWebSocket, which is basically the same as the one in SignalR with State property implemented.

marius-klimantavicius avatar Mar 03 '16 04:03 marius-klimantavicius

Nice, thanks for sharing!

Bobris avatar Mar 04 '16 21:03 Bobris