Skip to content

Commit

Permalink
Fix bug causing sporadic failures to handle admin HTTP requests
Browse files Browse the repository at this point in the history
Fix awaiting the processing of the HTTP request before returning control to the ASP.net framework.
This bug affected 'deploy' requests more often than others, probably because of the larger payload HTTP request body size in these cases.
In the previous version, logs from docker had shown related runtime exceptions like the following:
----
fail: ElmTime.Platform.WebService.StartupAdminInterface[0]
      Unobserved task exception in sender System.Runtime.CompilerServices.AsyncTaskMethodBuilder`1+AsyncStateMachineBox`1[System.Threading.Tasks.VoidTaskResult,ElmTime.Platform.WebService.StartupAdminInterface+<>c__DisplayClass34_3+<<Configure>b__20>d]
      System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Cannot access a disposed object.
      Object name: 'HttpRequestStream'.)
       ---> System.ObjectDisposedException: Cannot access a disposed object.
      Object name: 'HttpRequestStream'.
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestPipeReader.<ValidateState>g__ThrowObjectDisposedException|14_0()
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpRequestStream.ReadAsyncInternal(Memory`1 destination, CancellationToken cancellationToken)
         at System.Runtime.CompilerServices.PoolingAsyncValueTaskMethodBuilder`1.StateMachineBox`1.System.Threading.Tasks.Sources.IValueTaskSource<TResult>.GetResult(Int16 token)
         at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.ReadAsync(Memory`1 buffer, CancellationToken cancellationToken)
         at Microsoft.AspNetCore.WebUtilities.FileBufferingReadStream.<>c__DisplayClass46_0.<<CopyToAsync>g__CopyToAsyncImpl|0>d.MoveNext()
      --- End of stack trace from previous location ---
         at ElmTime.Platform.WebService.Asp.CopyRequestBody(HttpRequest httpRequest) in /app/elm-time/Platform/WebService/Asp.cs:line 104
         at ElmTime.Platform.WebService.StartupAdminInterface.<>c__DisplayClass34_3.<<Configure>g__deployElmApp|13>d.MoveNext() in /app/elm-time/Platform/WebService/StartupAdminInterface.cs:line 337
      --- End of stack trace from previous location ---
         at ElmTime.Platform.WebService.StartupAdminInterface.<>c__DisplayClass34_3.<<Configure>b__20>d.MoveNext() in /app/elm-time/Platform/WebService/StartupAdminInterface.cs:line 548
         --- End of inner exception stack trace ---
  • Loading branch information
Viir committed Jun 18, 2023
1 parent 7ccf754 commit 311fd8e
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -662,7 +662,7 @@ async System.Threading.Tasks.Task deployElmApp(bool initElmAppState)
apiRoute.methods
.FirstOrDefault(m => string.Equals(m.Key, context.Request.Method, StringComparison.InvariantCultureIgnoreCase));

if (matchingMethod.Value == null)
if (matchingMethod.Value is not { } matchingMethodDelegate)
{
var supportedMethodsNames =
apiRoute.methods.Keys.Select(m => m.ToUpperInvariant()).ToList();
Expand All @@ -683,7 +683,7 @@ async System.Threading.Tasks.Task deployElmApp(bool initElmAppState)
return;
}

matchingMethod.Value?.Invoke(context, publicAppHost);
await matchingMethodDelegate.Invoke(context, publicAppHost);
return;
}

Expand Down
2 changes: 1 addition & 1 deletion implement/elm-time/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ namespace ElmTime;

public class Program
{
public static string AppVersionId => "2023-06-16";
public static string AppVersionId => "2023-06-18";

private static int AdminInterfaceDefaultPort => 4000;

Expand Down
4 changes: 2 additions & 2 deletions implement/elm-time/elm-time.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
<TargetFramework>net7.0</TargetFramework>
<RootNamespace>ElmTime</RootNamespace>
<AssemblyName>elm-time</AssemblyName>
<AssemblyVersion>2023.0616.0.0</AssemblyVersion>
<FileVersion>2023.0616.0.0</FileVersion>
<AssemblyVersion>2023.0618.0.0</AssemblyVersion>
<FileVersion>2023.0618.0.0</FileVersion>
<Nullable>enable</Nullable>
<GenerateEmbeddedFilesManifest>true</GenerateEmbeddedFilesManifest>
</PropertyGroup>
Expand Down

0 comments on commit 311fd8e

Please sign in to comment.