Skip to content

Commit

Permalink
Stop handling new requests after the server has been stopped (#416)
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaliumhexacyanoferrat authored Nov 23, 2023
1 parent 078822f commit c12cbbe
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions API/Infrastructure/IServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ public interface IServer : IDisposable
/// </remarks>
string Version { get; }

/// <summary>
/// Specifies, whether the server still serves requests or
/// whether it is currently shut down.
/// </summary>
bool Running { get; }

/// <summary>
/// If enabled, components may provide additional information
/// allowing developers to further debug web applications.
Expand Down
2 changes: 2 additions & 0 deletions Engine/Infrastructure/ThreadedServer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ internal sealed class ThreadedServer : IServer

public string Version { get; }

public bool Running => !disposed;

public bool Development => Configuration.DevelopmentMode;

public IHandler Handler { get; private set; }
Expand Down
2 changes: 1 addition & 1 deletion Engine/Protocol/ClientHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ private async ValueTask HandlePipe(PipeReader reader)

RequestBuilder? request;

while ((request = await parser.TryParseAsync(buffer).ConfigureAwait(false)) is not null)
while (Server.Running && (request = await parser.TryParseAsync(buffer).ConfigureAwait(false)) is not null)
{
if (!await HandleRequest(request))
{
Expand Down

0 comments on commit c12cbbe

Please sign in to comment.