You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tinkerpop.apache.org by "Florian Hockmann (Jira)" <ji...@apache.org> on 2022/03/07 08:40:00 UTC
[jira] [Commented] (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."
[ https://issues.apache.org/jira/browse/TINKERPOP-2717?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17502133#comment-17502133 ]
Florian Hockmann commented on TINKERPOP-2717:
---------------------------------------------
Hey [~olivertowers], thanks for this bug report and the thorough analysis! Your suggestion for the fix also sounds good to me. Would you like to create a pull request to fix this?
> 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.4.13, 3.5.2
> Reporter: Oliver Towers
> Priority: Minor
>
> 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 {{MessageType.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, and notifies pending requests on the connection with the closed connection exception.
--
This message was sent by Atlassian Jira
(v8.20.1#820001)