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

Various exceptions #303

Closed
joshlang opened this issue Jul 4, 2019 · 2 comments
Closed

Various exceptions #303

joshlang opened this issue Jul 4, 2019 · 2 comments
Assignees
Labels

Comments

@joshlang
Copy link

joshlang commented Jul 4, 2019

I HATE to file bugs like this. It might not even be StreamJsonRpc-specific (Nerdbank?). But, in the event that it's useful at some point, here's an information dump.

We're using StreamJsonRpc over websockets. Usually everything's good. Sometimes, we go into a connect/disconnect loop where our connections immediately die. I captured some stack traces.

Error writing JSON RPC Result: IndexOutOfRangeException: Index was outside the bounds of the array.//StreamError/System.IndexOutOfRangeException: Index was outside the bounds of the array.
   at Nerdbank.Streams.BufferTextWriter.Write(Char value)
   at Newtonsoft.Json.JsonTextWriter.WriteEnd(JsonToken token)
   at Newtonsoft.Json.JsonWriter.AutoCompleteClose(JsonContainerType type)
   at Newtonsoft.Json.JsonWriter.InternalWriteEnd(JsonContainerType container)
   at Newtonsoft.Json.JsonWriter.WriteEndArray()
   at Newtonsoft.Json.JsonWriter.WriteEnd(JsonContainerType type)
   at Newtonsoft.Json.JsonWriter.WriteEnd()
   at Newtonsoft.Json.JsonWriter.AutoCompleteAll()
   at Newtonsoft.Json.JsonWriter.Close()
   at Newtonsoft.Json.JsonTextWriter.Close()
   at Newtonsoft.Json.JsonWriter.Dispose(Boolean disposing)
   at Newtonsoft.Json.JsonWriter.System.IDisposable.Dispose()
   at StreamJsonRpc.JsonMessageFormatter.WriteJToken(IBufferWriter`1 contentBuffer, JToken json)
   at StreamJsonRpc.JsonMessageFormatter.Serialize(IBufferWriter`1 contentBuffer, JsonRpcMessage message)
   at StreamJsonRpc.WebSocketMessageHandler.WriteCoreAsync(JsonRpcMessage content, CancellationToken cancellationToken)
   at StreamJsonRpc.MessageHandlerBase.WriteAsync(JsonRpcMessage content, CancellationToken cancellationToken)
   at StreamJsonRpc.JsonRpc.HandleRpcAsync(JsonRpcMessage rpc)
Error writing JSON RPC Result: ArgumentOutOfRangeException: Specified argument was out of the range of valid values.//StreamError/System.ArgumentOutOfRangeException: Specified argument was out of the range of valid values.
   at Nerdbank.Streams.BufferTextWriter.Write(ReadOnlySpan`1 buffer)
   at Nerdbank.Streams.BufferTextWriter.Write(String value)
   at Newtonsoft.Json.JsonTextWriter.WriteValueInternal(String value, JsonToken token)
   at Newtonsoft.Json.JsonTextWriter.WriteNull()
   at Newtonsoft.Json.JsonWriter.AutoCompleteClose(JsonContainerType type)
   at Newtonsoft.Json.JsonWriter.InternalWriteEnd(JsonContainerType container)
   at Newtonsoft.Json.JsonWriter.WriteEndObject()
   at Newtonsoft.Json.JsonWriter.WriteEnd(JsonContainerType type)
   at Newtonsoft.Json.JsonWriter.WriteEnd()
   at Newtonsoft.Json.JsonWriter.AutoCompleteAll()
   at Newtonsoft.Json.JsonWriter.Close()
   at Newtonsoft.Json.JsonTextWriter.Close()
   at Newtonsoft.Json.JsonWriter.Dispose(Boolean disposing)
   at Newtonsoft.Json.JsonWriter.System.IDisposable.Dispose()
   at StreamJsonRpc.JsonMessageFormatter.WriteJToken(IBufferWriter`1 contentBuffer, JToken json)
   at StreamJsonRpc.JsonMessageFormatter.Serialize(IBufferWriter`1 contentBuffer, JsonRpcMessage message)
   at StreamJsonRpc.WebSocketMessageHandler.WriteCoreAsync(JsonRpcMessage content, CancellationToken cancellationToken)
   at StreamJsonRpc.MessageHandlerBase.WriteAsync(JsonRpcMessage content, CancellationToken cancellationToken)
   at StreamJsonRpc.JsonRpc.HandleRpcAsync(JsonRpcMessage rpc)

and finally, it seems to be in the connect/disconnect loop when throwing:

Error writing JSON RPC Result: InvalidOperationException: This instance must be flushed before being reinitialized.//StreamError/System.InvalidOperationException: This instance must be flushed before being reinitialized.
   at Microsoft.Verify.Operation(Boolean condition, String message)
   at Nerdbank.Streams.BufferTextWriter.Initialize(IBufferWriter`1 bufferWriter, Encoding encoding)
   at StreamJsonRpc.JsonMessageFormatter.WriteJToken(IBufferWriter`1 contentBuffer, JToken json)
   at StreamJsonRpc.JsonMessageFormatter.Serialize(IBufferWriter`1 contentBuffer, JsonRpcMessage message)
   at StreamJsonRpc.WebSocketMessageHandler.WriteCoreAsync(JsonRpcMessage content, CancellationToken cancellationToken)
   at StreamJsonRpc.MessageHandlerBase.WriteAsync(JsonRpcMessage content, CancellationToken cancellationToken)
   at StreamJsonRpc.JsonRpc.HandleRpcAsync(JsonRpcMessage rpc)
@AArnott AArnott self-assigned this Jul 4, 2019
@AArnott AArnott added the bug label Jul 4, 2019
@AArnott
Copy link
Member

AArnott commented Jul 4, 2019

Thanks for the report. I've seen this once before. It's (gulp) good to know that it's a real bug. If you happen to have a repro, I'd love to see it. Otherwise I'll just do my best at code inspection and test writing to try to stumble upon the bug.

@AArnott
Copy link
Member

AArnott commented Jul 4, 2019

I suspect this is due to one or more bugs in Nerdbank.Streams. I'm closing this issue in favor of the one linked above (which references back to this one for details). You may want to follow that issue for status updates.

Thank you for the report.

@AArnott AArnott closed this as completed Jul 4, 2019
AArnott added a commit that referenced this issue Jul 7, 2019
#303 ended up being due to a customer reusing a formatter for several handlers. This is not allowed, but we may not have had documentation calling that out.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants