I have an C# WebAPI that let user upload file in chunks. The application works fine for http. But when I added https for my API I found out it works fine for small size of files, but for bigger file sizes (>60MB) the request just waits for 2 minutes and then just fails. After looking at the server log I found this exception:
Microsoft.AspNetCore.Connections.ConnectionResetException: An existing connection was forcibly closed by the remote host.
---> System.Net.Sockets.SocketException (10054): An existing connection was forcibly closed by the remote host.
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.<GetResult>g__ThrowSocketException|5_0(SocketError e)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.GetResult(Int16 token)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.DoReceive()
--- End of inner exception stack trace ---
at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
at System.IO.Pipelines.Pipe.GetReadAsyncResult()
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1ContentLengthMessageBody.ReadAsyncInternal(CancellationToken cancellationToken)
at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
at System.IO.Pipelines.PipeReader.CopyToAsyncCore[TStream](TStream destination, Func`4 writeAsync, CancellationToken cancellationToken)
at Infrastructure.LocalStorage.Domain.UploadFile.UploadChunkFileStreamService.SaveFileChunkAsync(UploadFileCommand command, String fileChunkPath)
What's even more crazy is it works fine for one server (we set up https on dev environment) but not for the other server. In both cases we are using IIS. Any idea how we can fix this issue? Am I missing any IIS configuration for HTTPS?
Note:
- we already made uploadReadAheadSize bigger to avoid 413 error.
- added the following code to my server as suggested on this post (however that's a
SocketException
NOTConnectionResetException
although the message are same)
ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12
- the file is being uploaded by a react app from the front-end.
Note 2: When I lower the number of chunks to upload to the server it works fine without any error. For now I am uploading 2 chunks at a time.