Skip to content

Asp.net core middleware, allows to wait for ongoing requests to finish.

License

Notifications You must be signed in to change notification settings

avtc/GracefullShutdown

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

10 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GracefullShutdown

Build status NuGet version Asp.net core middleware, allows to wait for ongoing requests to finish.

Sample usage:

public class Startup
{
  //...
  public IServiceProvider ConfigureServices(IServiceCollection services)
  {
     services.AddMvc();
     services.AddGracefullShutdown();
  }
  
  //...
  public void Configure(IApplicationBuilder app)
  {
    app.UseGracefullShutdown(options => {
      options.Redirect = true; 
      // Redirect: false - incoming requests will get 500 code after shutdown initiation
      //         : true  - incoming requests will be redirected with 308 code, and same url
      //                   for load balancer case
      options.ShutdownTimeout = TimeSpan.FromSeconds(20); 
      // default timeout is 10 seconds
    });

    app.UseMvc();
  }
  //...
}

Shutdown can be initiated using:

  • IApplicationLifetime.StopApplication()
  • Ctrl+C for self-hosted Kestrel server
  • SIGINT or SIGTERM signals for self-hosted Kestrel server in linux / docker

After shutdown is initiated, ongoing requests will be processed until timeout reached, new incoming requests will get 500 or 308 code.

GracefullShutdownOptions and GracefullShutdownState are thread safe and registered as singletons.

About

Asp.net core middleware, allows to wait for ongoing requests to finish.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published