Comments (8)
It seems like this has 3 parts to it:
a) Supporting graceful shutdown where clients are advised to connect to something else
b) Draining connections before actually shutting down - probably with a timeout
c) Eventing & signal model so that activating shutdown can tell the router to stop traffic, and when shutdown is complete, and the API to activate shutdown when told to by the router - assuming that app code will be listening to signals from the router.
from reverse-proxy.
The "Hosted" .NET app model (i.e. using Microsoft.Extensions.Hosting) on which ASP.NET Core is based has a graceful shutdown model and Kestrel participates in it already I believe. When shutdown is requested, Kestrel stops accepting new connections and drains existing ones (I'm not sure if it puts Connection: close
in but that could be added). If a (configurable) timeout elapses, the server terminates more forcefully (yields back to Program.Main which will likely exit and terminate the process).
So I think we have (b) already and adding (a) is relatively straightforward.
For (c), we have the necessary event hooks (IApplicationLifetime.ApplicationStopping
). I'm not sure there's a clear enough "pattern" that we could just implement in YARP though. I think custom code would be the primary way users would interact with that.
from reverse-proxy.
Triage: We do also have (a) it turns out.
Sounds like we need at least a sample (and maybe even a feature) for signalling health state based on IApplicationLifetime
.
from reverse-proxy.
See the following as a follow on from c)
#125 - Having an API for querying and understanding proxy status
#124 - REST / gRPC endpoint to expose the data from the proxy
#123 - Dashboard showing that data
from reverse-proxy.
We achieve the first part (not ready state when starting/stopping/stopped) of c) in our services with a health check on IHostApplicationLifetime
that tracks the status (starting/started/stopping/stopped) and use that in the readiness check.
The second part, removing from the upstream Load Balancer (LB) before rejecting new connections, is a bit more tricky. It either needs an active call from the service (and response from the LB) to remove the instance from rotation on the LB OR some knowledge about the configuration of health checks on the LB (ex. 3 failed checks with 10 sec. check interval) to know how long we need to report as unhealthy to the LB so it will have us removed before we proceed with Stopping and rejecting new connections.
from reverse-proxy.
Seems to be working for Island Gateway with a 3min shutdown for Kestrel (long duration due to gRPC streaming).
Should look at how to gracefully shutdown inner protocols such as:
- gRPC streaming. Eg grpc/grpc-go#2888
- Web sockets
from reverse-proxy.
Triage: We should be able to just see it working on Island Gateway prototype.
Sample may be useful for everyone
from reverse-proxy.
Triage: Scenario which didn't need any work, unclear what to do in sample. Closing.
from reverse-proxy.
Related Issues (20)
- TaskCanceledException exceptions occurring randomly HOT 4
- YARP not able to detect UseRequestTimeouts middleware HOT 12
- Handling passive health check on multiple instances of Yarp
- How to configure HttpClient to use Default System Proxy HOT 1
- Got error when proxying POST request with form HOT 1
- Consider allowing query strings in health probes
- Encountering Looping Refresh Issue with Basic Authentication in YARP HOT 2
- Http.sys delegation should handle ERROR_OBJECT_NO_LONGER_EXISTS and try to re-attach to the queue
- YARP has a higher cpu usage than Nginx HOT 6
- AddPathRemovePrefix does not work HOT 5
- Slow Start Mode HOT 1
- Need Help: Incorrect URL Transformation HOT 2
- Unable to handle TaskCanceledExceptions in HttpForwarder.SendAsync HOT 2
- Can I preserve original subdomain on request? HOT 2
- Create method PickDestinationAsync in ILoadBalancingPolicy HOT 3
- How to map forwarder with `Host`? HOT 4
- Extra and not needed commas in documentation
- Add the `IForwarderService` interface to override the implementation logic of `ForwarderMiddleware` HOT 1
- Strange behavior of Request.Url HOT 2
- Through the yarp proxy svn, the file name will appear 502 at noon, and no detailed errors can be seen HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from reverse-proxy.