graphql-platform icon indicating copy to clipboard operation
graphql-platform copied to clipboard

Intermittent error: "Unable to cast object of type 'RootPathSegment' to type 'HotChocolate.IndexerPathSegment'"

Open prodrammer opened this issue 2 years ago • 0 comments

Is there an existing issue for this?

  • [X] I have searched the existing issues

Describe the bug

NOTE: Since I was not able to reproduce in a fresh solution, I had originally posted a question in the community slack. Pascal recommended I post an issue anyway. Again, I am willing to hop on a zoom call to demonstrate the reproduction of this bug. Perhaps together, we can squash this!

Users of my application have been periodically running into the following intermittent error:

System.InvalidCastException: Unable to cast object of type 'RootPathSegment' to type 'HotChocolate.IndexerPathSegment'

It seems as though this issue happens when a mutation throws an exception. The RootPathSegment exception takes precedence over the underlying exception and is the only exception returned to the client.

Steps to reproduce

NOTE: I was unable to reproduce outside my solution. I am willing to conduct a zoom meeting to demonstrate the reproduction.

  1. Run a query that returns a root object with a single property (i.e. "People") containing an array of 15 people or more with a single scalar property (i.e. "Id" of type "string").
  2. Rerun the same query.
  3. Run a mutation that throws an exception.
  4. The error is thrown

Relevant log output

fail: Unexpected Execution Error
      System.InvalidCastException: Unable to cast object of type 'RootPathSegment' to type 'HotChocolate.IndexerPathSegment'.
         at HotChocolate.Execution.Processing.ResultBuilder.ApplyNonNullViolations(List`1 errors, List`1 violations, HashSet`1 fieldErrors)
         at HotChocolate.Execution.Processing.ResultBuilder.BuildResult()
         at HotChocolate.Execution.OperationContextExtensions.BuildResult(OperationContext context)
         at HotChocolate.Execution.Processing.QueryExecutor.ExecuteInternalAsync(OperationContext operationContext, IImmutableDictionary`2 scopedContext)
         at HotChocolate.Execution.Pipeline.OperationExecutionMiddleware.ExecuteQueryOrMutationAsync(IRequestContext context, IBatchDispatcher batchDispatcher, IOperation operation, OperationContext operationContext)
         at HotChocolate.Execution.Pipeline.OperationExecutionMiddleware.ExecuteOperationAsync(IRequestContext context, IBatchDispatcher batchDispatcher, IOperation operation)
         at HotChocolate.Execution.Pipeline.OperationExecutionMiddleware.InvokeAsync(IRequestContext context, IBatchDispatcher batchDispatcher)
         at HotChocolate.Execution.Pipeline.OperationVariableCoercionMiddleware.InvokeAsync(IRequestContext context)
         at HotChocolate.Execution.Pipeline.OperationResolverMiddleware.InvokeAsync(IRequestContext context)
         at HotChocolate.Execution.Pipeline.OperationComplexityMiddleware.InvokeAsync(IRequestContext context)
         at HotChocolate.Execution.Pipeline.OperationCacheMiddleware.InvokeAsync(IRequestContext context)
         at HotChocolate.Execution.Pipeline.DocumentValidationMiddleware.InvokeAsync(IRequestContext context)
         at HotChocolate.Execution.Pipeline.DocumentParserMiddleware.InvokeAsync(IRequestContext context)
         at HotChocolate.Execution.Pipeline.DocumentCacheMiddleware.InvokeAsync(IRequestContext context)
         at HotChocolate.Execution.Pipeline.TimeoutMiddleware.InvokeAsync(IRequestContext context)
         at HotChocolate.Execution.Pipeline.ExceptionMiddleware.InvokeAsync(IRequestContext context)

Additional Context?

After some analysis, the error occurs at the following line of code:

https://github.com/ChilliCream/hotchocolate/blob/d4e9c3b5c2a5380a3c18557abb9d9637e683e1f1/src/HotChocolate/Core/src/Execution/Processing/Result/ResultBuilder.NonNullHandling.cs#:~:text=list.SetUnsafe(((IndexerPathSegment)path).Index%2C%20null)%3B

list.SetUnsafe(((IndexerPathSegment)path).Index, null);

I can set a breakpoint on that line of code and run several operations (including running the query mentioned in the repro steps once, followed by the mutation, and the query again) without issue. As soon as I run the aforementioned query twice followed by the aforementioned mutation, the RootPathSegment error occurs.

Product

Hot Chocolate

Version

13.0.0-preview.51

prodrammer avatar Sep 15 '22 17:09 prodrammer