-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make a GracefulShutdown helper in hyper-util #2862
Comments
Hi @seanmonstar I previously had a go at writing an implementation of this here: One issue I struggled with doing this in a seperate crate is that I need to call For now I worked around it by using a closure so the user has to call My other suggestion / question was about building a more general purpose "Connection Manager" which could have features similar to http://nginx.org/en/docs/http/ngx_http_limit_conn_module.html ? |
Hey! Not sure if this is still an outstanding issue, but I can take a stab at it. I've implemented something like this with tokio's I can whip up a little code example later, not at my computer right now. |
It is still outstanding :) I admit I'm less familiar with |
I was thinking that it would be easier to track the completion of the tasks instead of the connections themselves, which I agree with you on keeping it runtime-agnostic and using the usage pattern you mentioned. To that end, I think the example @jacob-pro provided is a step in the right direction. The issue with it is that connections aren't shutdown by the Alternatively, maybe having a Are either of these options going down the right path? I feel like I'm spinning my wheels trying to get something to work following the usage you laid out. I'm probably just missing something |
Note that `hyper` v1.0.0-rc4 replaces IO traits from `tokio` with its IO traits in `hyper::rt`. To solve the building problem, we can introduce `TokioIo` from `hyper-util` and wrap the `DefaultIncoming` by the `TokioIo`. Also, the `volo-grpc` uses `hyper` v0.14 with its auto-version (using both http1 and http2) and graceful shutdown, but the latest `hyper` and `hyper-util` cannot use the both features at the same time, so the version of `hyper` in `volo` has not been upgraded. Ref: - hyperium/hyper@f9f65b7 - hyperium/hyper#3013 - hyperium/hyper#2862 Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
Note that `hyper` v1.0.0-rc4 replaces IO traits from `tokio` with its IO traits in `hyper::rt`. To solve the building problem, we can introduce `TokioIo` from `hyper-util` and wrap the `DefaultIncoming` by the `TokioIo`. Also, the `volo-grpc` uses `hyper` v0.14 with its auto-version (using both http1 and http2) and graceful shutdown, but the latest `hyper` and `hyper-util` cannot use the both features at the same time, so the version of `hyper` in `volo` has not been upgraded. Ref: - hyperium/hyper@f9f65b7 - hyperium/hyper#3013 - hyperium/hyper#2862 Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
Note that `hyper` v1.0.0-rc4 replaces IO traits from `tokio` with its IO traits in `hyper::rt`. To solve the building problem, we can introduce `TokioIo` from `hyper-util` and wrap the `DefaultIncoming` by the `TokioIo`. Also, the `volo-grpc` uses `hyper` v0.14 with its auto-version (using both http1 and http2) and graceful shutdown, but the latest `hyper` and `hyper-util` cannot use the both features at the same time, so the version of `hyper` in `volo` has not been upgraded. Ref: - hyperium/hyper@f9f65b7 - hyperium/hyper#3013 - hyperium/hyper#2862 Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
@seanmonstar can I pick this up together with the issue to add a Server to hyper-util? |
I think the two items are probably worth being separate. The |
* feat: introduce volo-http crate * feat(volo-http): introduce route id > The `matchit::Router` cannot be converted to `Iterator`, so using > `matchit::Router<DynService>` is not convenient enough. > To solve the problem, we refer to the implementation of `axum` and > introduce a `RouteId` as a bridge, the `matchit::Router` only handles > some IDs and each ID corresponds to a `DynService`. * feat(volo-http): wrap `DynService` with `Route` > With tie type `Route`, it can support `Service`, `Handler` and so on. * feat(volo-http): make handler more powerful > With this commit, there is no need to keep `HttpContext` in handler > function. Like axum, anything with `FromContext` or `FromRequest` > trait can be used as arguments of a handler. * chore(volo-http): bump to hyper 1.0.0 > Note that `hyper` v1.0.0-rc4 replaces IO traits from `tokio` with its > IO traits in `hyper::rt`. To solve the building problem, we can > introduce `TokioIo` from `hyper-util` and wrap the `DefaultIncoming` > by the `TokioIo`. > > Also, the `volo-grpc` uses `hyper` v0.14 with its auto-version > (using both http1 and http2) and graceful shutdown, but the latest > `hyper` and `hyper-util` cannot use the both features at the same > time, so the version of `hyper` in `volo` has not been upgraded. > > Ref: > - hyperium/hyper@f9f65b7 > - hyperium/hyper#3013 > - hyperium/hyper#2862 * feat(volo-http): support `with_state` * fix(volo-http): fix timeout problem of graceful shutdown > With the previous codes, server could not stop immediately after > pressing Ctrl+C, but waited until timeout before exiting. > > This commit uses the same approach as "volo-thrift" and the problem > has been resolved. * feat(volo-http): support fallback > This commit supports fallback in `Router` and `MethodRouter`. With > `fallback`, when no route or method can handle the request, the > `fallback` will be called and the specified response will be returned. * feat(volo-http): add `TimeoutLayer` with response > This commit adds a `TimeoutLayer` for `volo-http` which can use a > function as a callback and when timeout occurs, it will return a > response by the callback. * chore(volo-http): bump version to `0.1.0` * credits: update license of axum --------- Signed-off-by: Gwo Tzu-Hsing <gotzehsing@gmail.com> Signed-off-by: Zheng Li <875543533@qq.com> Signed-off-by: bobozhengsir <bobozhengsir@gmail.com> Signed-off-by: Yu Li <liyu.yukiteru@bytedance.com>
Sorry @seanmonstar and @dswij for the confusion. Deleted the repo attached to the original PR not realising the PR was attached to it. It is now recreated as-is in hyperium/hyper-util#108 |
With the removal of
hyper::Server
, the graceful shutdown stuff would disappear. We want to continue to provide a helper to do that, in hyper-util, but make it also able to be used with timeouts. Perhaps something like this:The text was updated successfully, but these errors were encountered: