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

GraphQL Client is not able to reconnect if graphQL server restart #180

Open
akoliya003 opened this issue Mar 4, 2020 · 9 comments
Open
Labels
bug Something isn't working

Comments

@akoliya003
Copy link

akoliya003 commented Mar 4, 2020

Hi,

GraphQL Client is not able to reconnect if graphQL server restart.
In my local copy below is the change I have added.

GraphQL.Client --> Http --> GraphQLHttpWebSocket.cs --> _receiveResultAsync(...) --> 
			.....
                         catch (Exception e)
			{
				**await _closeAsync().ConfigureAwait(false);
				clientWebSocket?.Dispose();**
				Debug.WriteLine($"exception thrown while receiving websocket data: {e}");
				throw;
			}

You may also have some better way.

-----------------------------------------------------------------------------------------------
WebSocketException: The remote party closed the WebSocket connection without completing the close handshake. (WebSocketError ConnectionClosedPrematurely, ErrorCode 0, NativeErrorCode 0
WebSocketException: The remote party closed the WebSocket connection without completing the close handshake. (WebSocketError ConnectionClosedPrematurely, ErrorCode 0, NativeErrorCode 0
System.NullReferenceException: Object reference not set to an instance of an object.
   at GraphQL.Client.Http.Websocket.GraphQLHttpWebsocketHelpers.<>c__DisplayClass0_0`1.<CreateSubscriptionStream>b__3(Exception e)
System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake. ---> System.IO.IOException: Unable to transfer data on the transport connection: Broken pipe. ---> System.Net.Sockets.SocketException: Broken pipe
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.WebSockets.ManagedWebSocket.<SendFrameFallbackAsync>d__56.MoveNext()
   at System.Net.WebSockets.ManagedWebSocket.<SendFrameFallbackAsync>d__56.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at GraphQL.Client.Http.Websocket.GraphQLHttpWebSocket.<_sendWebSocketRequest>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at GraphQL.Client.Http.Websocket.GraphQLHttpWebsocketHelpers.<>c__DisplayClass0_0`1.<<CreateSubscriptionStream>b__5>d.MoveNext()
@rose-a rose-a added the bug Something isn't working label Mar 4, 2020
@rose-a
Copy link
Collaborator

rose-a commented Mar 4, 2020

I'm aware of an issue with the reconnect capability, seems there is a threading problem within the observable chain... Hopefully I'll be able to fix this in the coming days

@akoliya003
Copy link
Author

akoliya003 commented Mar 4, 2020 via email

@rose-a
Copy link
Collaborator

rose-a commented Mar 4, 2020

The exception is as expected and you cannot call closeAsync() there because the websocket is in an aborted state. This is taken care of by InitializeWebSocket() which disposes the old websocket instance if it's in a bad state and creates a new one...

This should automatically happen through the Retry() method in the subscriptions observable chain.

Maybe you could configure a custom GraphQLHttpClientOptions.BackOffStrategy and check if this method is invoked after you shut down the server?

@rose-a
Copy link
Collaborator

rose-a commented Mar 4, 2020

Somehow this seems to be related with #161...

@akoliya003
Copy link
Author

akoliya003 commented Mar 4, 2020

I tried adding custom GraphQLHttpClientOptions.BackOffStrategy and checked that method is not invoked at all.

Instead of retries it raise below exception:

-------
WebSocketException: The remote party closed the WebSocket connection without completing the close handshake. (WebSocketError ConnectionClosedPrematurely, ErrorCode 0, NativeErrorCode 0
WebSocketException: The remote party closed the WebSocket connection without completing the close handshake. (WebSocketError ConnectionClosedPrematurely, ErrorCode 0, NativeErrorCode 0
System.NullReferenceException: Object reference not set to an instance of an object.
   at GraphQL.Client.Http.Websocket.GraphQLHttpWebsocketHelpers.<>c__DisplayClass0_0`1.<CreateSubscriptionStream>b__3(Exception e)
System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake. ---> System.IO.IOException: Unable to transfer data on the transport connection: Broken pipe. ---> System.Net.Sockets.SocketException: Broken pipe
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.WebSockets.ManagedWebSocket.<SendFrameFallbackAsync>d__56.MoveNext()
   at System.Net.WebSockets.ManagedWebSocket.<SendFrameFallbackAsync>d__56.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at GraphQL.Client.Http.Websocket.GraphQLHttpWebSocket.<_sendWebSocketRequest>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at GraphQL.Client.Http.Websocket.GraphQLHttpWebsocketHelpers.<>c__DisplayClass0_0`1.<<CreateSubscriptionStream>b__5>d.MoveNext()
---------------

@akoliya003
Copy link
Author

akoliya003 commented Mar 4, 2020 via email

@rose-a
Copy link
Collaborator

rose-a commented Mar 9, 2020

that exception all the way pass to application

Where does that exception surface? Does it call OnError on your subscription?

@akoliya003
Copy link
Author

akoliya003 commented Mar 11, 2020

Yes,

Below is the Exception details:

----------------------
testGraphQL.WScoreUpdate
WebSocketException: The remote party closed the WebSocket connection without completing the close handshake. (WebSocketError ConnectionClosedPrematurely, ErrorCode 424189040, NativeErrorCode 424189040
WebSocketException: The remote party closed the WebSocket connection without completing the close handshake. (WebSocketError ConnectionClosedPrematurely, ErrorCode 0, NativeErrorCode 0
System.NullReferenceException: Object reference not set to an instance of an object.
   at GraphQL.Client.Http.Websocket.GraphQLHttpWebsocketHelpers.<>c__DisplayClass0_0`1.<CreateSubscriptionStream>b__3(Exception e)
System.Net.WebSockets.WebSocketException (0x80004005): The remote party closed the WebSocket connection without completing the close handshake. ---> System.IO.IOException: Unable to transfer data on the transport connection: Broken pipe. ---> System.Net.Sockets.SocketException: Broken pipe
   --- End of inner exception stack trace ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Net.WebSockets.ManagedWebSocket.<SendFrameFallbackAsync>d__56.MoveNext()
   at System.Net.WebSockets.ManagedWebSocket.<SendFrameFallbackAsync>d__56.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at GraphQL.Client.Http.Websocket.GraphQLHttpWebSocket.<_sendWebSocketRequest>d__24.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at GraphQL.Client.Http.Websocket.GraphQLHttpWebsocketHelpers.<>c__DisplayClass0_0`1.<<CreateSubscriptionStream>b__5>d.MoveNext()
----------

@rose-a
Copy link
Collaborator

rose-a commented Mar 16, 2020

Did you pass a custom exception handler? This exception is normally swallowed by and causes a Retry on the subscription.

Please also update to the latest version of this lib, as I made some optimizations to the code behind...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants