You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by "Oliver Towers (Jira)" <ji...@apache.org> on 2022/03/04 19:38:00 UTC

[jira] [Created] (TINKERPOP-2717) Gremlin.NET : WebSocketConnection does not check for MessageType.Close, causing error InvalidOperationException: "Received data deserialized into null object message. Cannot operate on it."

Oliver Towers created TINKERPOP-2717:
----------------------------------------

             Summary: Gremlin.NET : WebSocketConnection does not check for MessageType.Close, causing error InvalidOperationException: "Received data deserialized into null object message. Cannot operate on it."
                 Key: TINKERPOP-2717
                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2717
             Project: TinkerPop
          Issue Type: Bug
          Components: dotnet
    Affects Versions: 3.5.2, 3.4.13
            Reporter: Oliver Towers


h2. Issue:

If the server sends a valid Close websocket message to the client, the client will throw `InvalidOperationException` rather than acknowledge/cleanup the connection gracefully.

See relevant point where exception is thrown. [here|https://github.com/apache/tinkerpop/blob/7835e7a2c3b19a14f196525da844a2e35ba5a105/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs#L123]

Close messages from the server can be expected when the server is doing a graceful shutdown, and clients would be expected to reconnect.

h2. Details:

A Close websocket message being received by ClientWebSocket, [WebSocketReceiveResult.MessageType|https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets.websocketreceiveresult.messagetype?view=net-6.0] will return `Close`. In this case, the message buffer will be zero-bytes, see these [remarks|https://docs.microsoft.com/en-us/dotnet/api/system.net.websockets.websocketreceiveresult.count?view=net-6.0#remarks].

Currently, Gremlin.NET does not check for this message type in [WebSocketConnection.ReceiveMessageAsync|https://github.com/apache/tinkerpop/blob/7835e7a2c3b19a14f196525da844a2e35ba5a105/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs#L92] and return a zero-length buffer. In [Connection.HandleReceiveAsync|https://github.com/apache/tinkerpop/blob/7835e7a2c3b19a14f196525da844a2e35ba5a105/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs#L118], the attempt to deserialize the empty buffer returns `null` and the check fails.

h2. Potential Fix

# If `MessageType == Close` Throw a new connection closed exception from `WebSocketConnection.ReceiveMessageAsync` which includes `WebSocketReceiveResult.CloseStatus` and WebSocketReceiveResult.CloseDescription` in the exception message and as properties.
# This will be caught in `Connection.HandleRecieveAsync` and treated as fatal and will call `CloseConnectionBecauseOfFailureAsync` and will handle completing the close handshake with server per WebSocket protocol, and notifies pending requests on the connection with the exception.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)