gRPC-web stops communicating after the first communication of a large string submission
What version of gRPC and what language are you using?
C#
Server's configuration:
<PackageReference Include="Grpc.AspNetCore" Version="2.30.0" />
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.30.0" />
Client's configuration:
<ItemGroup>
<PackageReference Include="Google.Protobuf" Version="3.12.3" />
<PackageReference Include="Grpc.Net.Client" Version="2.30.0" />
<PackageReference Include="Grpc.Net.Client.Web" Version="2.30.0" />
<PackageReference Include="Grpc.Tools" Version="2.30.0">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
</ItemGroup>
What operating system (Linux, Windows,...) and version?
Azure App Services (Windows) Development environment: Windows 10, Visual Studio 2019
What runtime / compiler are you using (e.g. .NET Core SDK version dotnet --info)
.net core info: C:\Temp>dotnet --info .NET Core SDK (reflecting any global.json): Version: 3.1.302 Commit: 41faccf259
Runtime Environment: OS Name: Windows OS Version: 10.0.17763 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\3.1.302\
Host (useful for support): Version: 3.1.6 Commit: 3acd9b0cd1
.NET Core SDKs installed: 3.1.102 [C:\Program Files\dotnet\sdk] 3.1.202 [C:\Program Files\dotnet\sdk] 3.1.302 [C:\Program Files\dotnet\sdk]
.NET Core runtimes installed: Microsoft.AspNetCore.All 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.All 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All] Microsoft.AspNetCore.App 2.1.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.1 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 2.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 3.1.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
What did you do?
We followed the same pattern as the Browser App suggests to setup a gRPC-web service. The client code which is a C# code prepares and submits a 2,937,558 bytes string to the gRPC-web application. Submitting the string to the gRPC-web app on development machine is consistently successful. Getting the same string submitted to the same app hosted on Azure results into success ONLY in the first call and all subsequent calls consistently fail. To recover from this situation, we have to restart the App Service on Azure. We also scaled up the service to P3V2 plan but that did not lead to a success.
What did you expect to see?
The gRPC-web app hosted on Azure should not fail in the subsequent calls.
What did you see instead?
Failure and exception in the client application per the following stack trace:
dbug: Grpc.Net.Client.Internal.GrpcCall[1] Starting gRPC call. Method type: 'Unary', URI: 'https://MASKED1234.azurewebsites.net/MASKED1234.PayloadSubmission/Submit'. dbug: Grpc.Net.Client.Internal.GrpcCall[18] Sending message. fail: Grpc.Net.Client.Internal.GrpcCall[20] Error sending message. System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request.. ---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request. --- End of inner exception stack trace --- at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Security.SslStream.
g__CompleteAsync|210_1[TWriteAdapter](ValueTask writeTask, Byte[] bufferToReturn) at System.Net.Security.SslStream.WriteAsyncInternal[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory 1 buffer) at System.Net.Http.HttpConnection.WriteAsync(ReadOnlyMemory1 source) at System.Net.Http.HttpConnection.ChunkedEncodingWriteStream.g__WriteChunkAsync|2_0(HttpConnection connection, ReadOnlyMemory 1 buffer) at Grpc.Net.Client.Web.Internal.Base64RequestStream.WriteAsync(ReadOnlyMemory1 data, CancellationToken cancellationToken) at Grpc.Net.Client.StreamExtensions.WriteMessageAsync[TMessage](Stream stream, ILogger logger, TMessage message, Action2 serializer, String grpcEncoding, Nullable1 maximumMessageSize, Dictionary2 compressionProviders, CallOptions callOptions) fail: Grpc.Net.Client.Internal.GrpcCall[6] Error starting gRPC call. System.Threading.Tasks.TaskCanceledException: The operation was canceled. ---> System.Net.Http.HttpRequestException: Error while copying content to a stream. ---> System.IO.IOException: Unable to read data from the transport connection: The I/O operation has been aborted because of either a thread exit or an application request.. ---> System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request. --- End of inner exception stack trace --- at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken) at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token) at System.Net.Security.SslStream.<WriteSingleChunk>g__CompleteAsync|210_1[TWriteAdapter](ValueTask writeTask, Byte[] bufferToReturn) at System.Net.Security.SslStream.WriteAsyncInternal[TWriteAdapter](TWriteAdapter writeAdapter, ReadOnlyMemory1 buffer) at System.Net.Http.HttpConnection.WriteAsync(ReadOnlyMemory1 source) at System.Net.Http.HttpConnection.ChunkedEncodingWriteStream.<WriteAsync>g__WriteChunkAsync|2_0(HttpConnection connection, ReadOnlyMemory1 buffer) at Grpc.Net.Client.Web.Internal.Base64RequestStream.WriteAsync(ReadOnlyMemory1 data, CancellationToken cancellationToken) at Grpc.Net.Client.StreamExtensions.WriteMessageAsync[TMessage](Stream stream, ILogger logger, TMessage message, Action2 serializer, String grpcEncoding, Nullable1 maximumMessageSize, Dictionary2 compressionProviders, CallOptions callOptions) at Grpc.Net.Client.Internal.PushUnaryContent`2.WriteMessageCore(ValueTask writeMessageTask) at System.Net.Http.HttpContent.CopyToAsyncCore(ValueTask copyTask) --- End of inner exception stack trace --- at System.Net.Http.HttpContent.CopyToAsyncCore(ValueTask copyTask) at Grpc.Net.Client.Web.Internal.GrpcWebRequestContent.SerializeTextToStreamAsync(Stream stream) at System.Net.Http.HttpContent.CopyToAsyncCore(ValueTask copyTask) at System.Net.Http.HttpConnection.SendRequestContentAsync(HttpRequestMessage request, HttpContentWriteStream stre
Anything else we should know about your project / environment?
The gRPC-web application was deployed as a self-contained application to Azure. The server does not log any failures or exceptions.
I haven't seen this before. You said it always works on your development machine but fails when deployed to Azure, which tends to indicate it is an issue with the Azure environment. I'm not an Azure expert so I don't know how you would debug from here.
@JamesNK not sure who is the right person who can look into this problem at Azure team. Bottom line the issue I described is happening.
@JamesNK I realized the following exceptions on Azure Server after making a slight change in the code. The large string which was a JSON string is now transmitted by a google.protobuf.Struct object.
Grpc.Core.RpcException: at Grpc.AspNetCore.Server.Internal.PipeExtensions.TryReadMessage (Grpc.AspNetCore.Server, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad) at Grpc.AspNetCore.Server.Internal.PipeExtensions+
d__13`1.MoveNext (Grpc.AspNetCore.Server, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad)
And this one:
Grpc.Core.RpcException: at Grpc.AspNetCore.Server.Internal.PipeExtensions.TryReadMessage (Grpc.AspNetCore.Server, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad) at Grpc.AspNetCore.Server.Internal.PipeExtensions+
d__13 1.MoveNext (Grpc.AspNetCore.Server, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Threading.Tasks.ValueTask1.get_Result (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.ValueTaskAwaiter1.GetResult (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Grpc.AspNetCore.Server.Internal.CallHandlers.UnaryServerCallHandler3+d__2.MoveNext (Grpc.AspNetCore.Server, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Grpc.AspNetCore.Server.Internal.CallHandlers.ServerCallHandlerBase`3+< g__AwaitHandleCall|8_0>d.MoveNext (Grpc.AspNetCore.Server, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad)
Also this one:
Microsoft.AspNetCore.Connections.ConnectionResetException: at Microsoft.AspNetCore.Server.IIS.Core.IO.AsyncIOOperation.GetResult (Microsoft.AspNetCore.Server.IIS, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext+
d__337.MoveNext (Microsoft.AspNetCore.Server.IIS, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.IO.Pipelines.PipeCompletion.ThrowLatchedException (System.IO.Pipelines, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) at System.IO.Pipelines.Pipe.GetReadResult (System.IO.Pipelines, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) at System.IO.Pipelines.Pipe.GetReadAsyncResult (System.IO.Pipelines, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) at System.IO.Pipelines.Pipe+DefaultPipeReader.GetResult (System.IO.Pipelines, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext+ d__334.MoveNext (Microsoft.AspNetCore.Server.IIS, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Microsoft.AspNetCore.Server.IIS.Core.HttpRequestStream+ d__11.MoveNext (Microsoft.AspNetCore.Server.IIS, Version=3.1.6.0, Culture=neutral, PublicKeyToken=adb9793829ddae60) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.IO.Pipelines.StreamPipeReader+ d__27.MoveNext (System.IO.Pipelines, Version=4.0.2.1, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Grpc.AspNetCore.Web.Internal.Base64PipeReader+ d__11.MoveNext (Grpc.AspNetCore.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad) at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess (System.Private.CoreLib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=7cec85d7bea7798e) at Grpc.AspNetCore.Server.Internal.PipeExtensions+ d__13`1.MoveNext (Grpc.AspNetCore.Server, Version=2.0.0.0, Culture=neutral, PublicKeyToken=d754f35622e28bad) Inner exception System.Runtime.InteropServices.COMException handled at Microsoft.AspNetCore.Server.IIS.Core.IO.AsyncIOOperation.GetResult:
This test app is able to successfully call a test gRPC-Web website that is hosted in Azure. I believe it is hosted in Azure Linux so it isn't an exact reproduction.
To test whether it is an IIS issue I also ran the app locally calling a gRPC server hosted in IIS Express. That also worked successfully.
I don't know what the problem is, but it doesn't seem like an issue in gRPC.
@JamesNK is your server side using the same dotnet core version as what I outlined before?
@Arash-Sabet have you tried setting MaxReceiveMessageSize (https://docs.microsoft.com/en-us/aspnet/core/grpc/configuration?view=aspnetcore-3.1)?
I don't think it should matter as you're below the default 4MB but it's about the only thing that springs to mind at the moment
@JamesNK is your server side using the same dotnet core version as what I outlined before?
I tested with .NET Core 3.1
@Harkole I set MaxReceiveMessageSize explicitly to 5 MB and it did not help.
@JamesNK The following settings are my server's configurations:
Version: 3.1.302 (.net core) Commit: 41faccf259
<PackageReference Include="Grpc.AspNetCore" Version="2.30.0" />
<PackageReference Include="Grpc.AspNetCore.Web" Version="2.30.0" />
@Arash-Sabet is it possible that it's a timeout that's occurring when working the data?
I can't find the information at the moment but seem to recall there is a default timeout on gRPC operations of 30 seconds, I'm wondering if the error is a little misleading and it's not the payload but the process that's simply timing out? This may explain why @JamesNK is seeing a success when testing it...
@Harkole I ran the test (client code) that @JamesNK shared and it was fine in my end too. My protobuf file is a bit different from "Greeting application's" and it has a few extra fields but they shouldn't matter. The issue gets more complicated when the development machine exhibits a different behavior from Azure App. The gRPC communication on the development machine gives up after 50+ successful communications but the cloud's fails right after the first one. It will be great if James could tell us a bit about his server's configuration e.g. the exact .net core version, commit#, nuget packages' versions, etc.
@Arash-Sabet that certainly rules out what I was initially thinking!
There was an application I worked on, which when set up which was streaming file data over gRPC and caused a few issues with hosting inside IIS but when configured to use Kestrel it runs fine. This was on a VM (Server 2016 Standard) though and not in Azure Application Services
This test app is able to successfully call a test gRPC-Web website that is hosted in Azure. I believe it is hosted in Azure Linux so it isn't an exact reproduction.
To test whether it is an IIS issue I also ran the app locally calling a gRPC server hosted in IIS Express. That also worked successfully.
I don't know what the problem is, but it doesn't seem like an issue in gRPC.
Is it possible to test against a Kestrel configuration instead of IIS? The reply from @JamesNK above suggests it probably won't make a difference, however it never hurts to test these things out fully!
@Harkole Yes, I will give that a try and let you know the results, hopefully by the end of this week or mid next week.
@Harkole I ran the test against a Kestrel configuration on a VM hosted in premises and did not experience the issue that I initially reported. So, apparently IIS is the root cause of the problem. /cc @JamesNK
Sorry I don't know what else to suggest, at this stage it is either the grpc-web has a limitation or bug or that IIS has a configuration issue but I don't know how to test either solution properly. My only thought would be a clean IIS installation with no configuration changes except those required to run this one app?
If I am correct at the moment iis does not support it => https://docs.microsoft.com/en-us/aspnet/core/grpc/?view=aspnetcore-3.1
If I am correct at the moment iis does not support it => https://docs.microsoft.com/en-us/aspnet/core/grpc/?view=aspnetcore-3.1
gRPC-web is supposed to address the problem for time being. @daanflore
@Arash-Sabet Can you provide a repro app since we can't seem to repro (ConsoleApp51.zip works)
@BrennanConroy Is the server application serving ConsoleApp51.zip hosted as a Kestrel on a VM? My server application was hosted on Azure App Services and also IIS Express locally that both exhibited the issue. After running the server application as a Kestrel app on a VM, the issue disappeared.
I couldn't recreate the gRPC-Web issue in either App service, or in Kestrel - https://github.com/grpc/grpc-dotnet/issues/997#issuecomment-663807873
And this issue only shows up in App service, which indicates it isn't a problem with the grpc-dotnet library.
I'm going to close this unless there are any other suggestions.