[ 
https://issues.apache.org/jira/browse/TINKERPOP-2019?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16571716#comment-16571716
 ] 

Florian Hockmann commented on TINKERPOP-2019:
---------------------------------------------

Thanks for bringing this to our attention, [~samimajed]. I just formatted the 
issue description a bit.
{quote}Would it be possible to identify if this is indeed a bug on Gremlin.NET?
{quote}
Sure, this might be a bug in Gremlin.Net but I'm afraid it could be hard to 
track down. If you were able to create a minimal code example that reproduces 
the problem, ideally with just Gremlin Server and not CosmosDB, that would be 
extremely helpful for us to find and understand the problem better and then 
hopefully also fix it.

Regarding work-arounds, without knowing what causes the problem I don't know 
how you could try to avoid it. You could of course simply implement a retry 
policy for the {{InvalidOperationException}}.
{quote}After looking at GitHub's WebSocketConnection class, I don't see any 
orchestration between SendMessageAsync's {{_client.SendAsync}} (currently line 
54) and ReceiveMessageAsync's {{_client.ReceiveAsync}} (currently line 66).
{quote}
You're right, there is no orchestration directly in that class but the 
{{WebSocketConnection}} class is an {{internal}} class and the only usage of 
these two methods is [in the {{Connection}} 
class|https://github.com/apache/tinkerpop/blob/dd09c059566a0e4d48845ac1dcc789ae075ff10b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs#L56]:
{code:java}
public async Task<IReadOnlyCollection<T>> SubmitAsync<T>(RequestMessage 
requestMessage)
{
        await SendAsync(requestMessage).ConfigureAwait(false);
        return await ReceiveAsync<T>().ConfigureAwait(false);
}
{code}
As this small snippet already shows, {{ReceiveAsync}} will only be called after 
{{SendAsync}} was awaited. So, it should not be possible for these two 
functions to be executed at the same time. [Each {{Connection}} also has its 
own 
{{WebSocketConnection}}|https://github.com/apache/tinkerpop/blob/dd09c059566a0e4d48845ac1dcc789ae075ff10b/gremlin-dotnet/src/Gremlin.Net/Driver/Connection.cs#L41]:
{code:java}
private readonly WebSocketConnection _webSocketConnection = new 
WebSocketConnection();
{code}
 
 However, your error message sounds more like {{SendAsync}} gets called two 
times simultaneously:
{quote}There is already one outstanding '*SendAsync*' call for this WebSocket 
instance.
 [...]
 System.InvalidOperationException at 
Gremlin.Net.Driver.WebSocketConnection+<*SendMessageAsync*>d__5.MoveNext
{quote}
which should also not be possible as the aforementioned method {{SubmitAsync}} 
is also only called in one place and the {{Connection}} object gets only 
returned to the {{ConnectionPool}} [after being 
awaited|https://github.com/apache/tinkerpop/blob/dd09c059566a0e4d48845ac1dcc789ae075ff10b/gremlin-dotnet/src/Gremlin.Net/Driver/GremlinClient.cs#L70]:
{code:java}
using (var connection = await 
_connectionPool.GetAvailableConnectionAsync().ConfigureAwait(false))
{
    return await 
connection.SubmitAsync<T>(requestMessage).ConfigureAwait(false);
}
{code}
So, I have no idea right now how this exception could have occurred.

Did you see anything unusual before this exception occurred? Was there maybe 
another exception before?

> Gremlin.Net.Driver.WebSocketConnection throws System.InvalidOperationException
> ------------------------------------------------------------------------------
>
>                 Key: TINKERPOP-2019
>                 URL: https://issues.apache.org/jira/browse/TINKERPOP-2019
>             Project: TinkerPop
>          Issue Type: Bug
>          Components: dotnet
>    Affects Versions: 3.3.3
>         Environment: Azure App Service
>            Reporter: Sami
>            Priority: Critical
>
> We're getting the following {{System.InvalidOperationException}} error 
> message:
> {code:c#}
> "There is already one outstanding 'SendAsync' call for this WebSocket 
> instance. ReceiveAsync and SendAsync can be called simultaneously, but at 
> most one outstanding operation for each of them is allowed at the same time.
> Problem Id:
> System.InvalidOperationException at 
> Gremlin.Net.Driver.WebSocketConnection+<SendMessageAsync>d__5.MoveNext"{code}
>  
>  We get this exception sporadically and only a few times out of thousands. 
> Unfortunately we have not been able to reproduce it.
>   
>  I understand that when dealing with web sockets, it is allowed to have only 
> a single pending "send" or a single pending "receive".
>   
>  After looking at GitHub's WebSocketConnection class, I don't see any 
> orchestration between SendMessageAsync's {{_client.SendAsync}} (currently 
> line 54) and ReceiveMessageAsync's {{_client.ReceiveAsync}} (currently line 
> 66). 
>   
>  Reference Link: 
>  
> [https://github.com/apache/tinkerpop/blob/master/gremlin-dotnet/src/Gremlin.Net/Driver/WebSocketConnection.cs]
>   
>  I'm wondering if not having orchestration in the WebSocketConnection class 
> to keep the single pending "send" or a single pending "receive" rule may be 
> the cause. 
>   
>  In our .NET Core web api application, we create the GremlinConnection as a 
> singleton in Startup.cs and then have one central call that makes Gremlin 
> calls; i.e. it's a very straightforward implementation.
>   
>  Startup.cs:
> {code:c#}
> public void ConfigureServices(IServiceCollection services)
> {
>     //...other stuff removed for brevity
>     services.AddSingleton<IGremlinConnection, GremlinConnection>();
> }{code}
>  
>  Reader.cs:
> {code:c#}
> public async Task<IReadOnlyCollection<dynamic>> ExecuteGremlinQuery(string 
> query)
> {
>     try
>     {
>         return await _gremlinConnection.Client.SubmitAsync<dynamic>(query);
>     }
>     catch (Gremlin.Net.Driver.Exceptions.ResponseException responseException)
>     {
>         //our error handling removed for brevity!    
>     }
> }{code}
>   
>  We use the Gremlin.Net version 3.3.3 nuget package and the 
> Microsoft.NETCore.App SDK
>   
>  Would it be possible to identify if this is indeed a bug on Gremlin.NET? 
>  And if it is, any thoughts on a best-practice (temporary) work-around that 
> we can implement?



--
This message was sent by Atlassian JIRA
(v7.6.3#76005)

Reply via email to