cloudwego / hertz

Go HTTP framework with high-performance and strong-extensibility for building micro-services.
https://www.cloudwego.io
Apache License 2.0
5.34k stars 525 forks source link

set server context default timeout #432

Closed godsoul closed 1 year ago

godsoul commented 1 year ago

当hertz做服务端的时候,客户端没传context,可以给context.Context设置个默认超时时间。

li-jin-gou commented 1 year ago

Hertz Server does not use context to control the timeout of requests. It provides write_timeout and read_timeout configurations.

li-jin-gou commented 1 year ago

I think this could provide a timeout middleware that would help the business use context to control the timeout but we need to know that there is nothing we can do to stop the goroutine from continuing to execute even if we control the timeout. refer to https://github.com/valyala/fasthttp/issues/1447

godsoul commented 1 year ago

I want hetz context -> gorm WithContext -> redis context, but i got hertz context is context.Background(),no set timeout.

welkeyever commented 1 year ago

It is available to set it according to your business logic through a middleware, and pass it through your third part SDKs. More info: https://www.cloudwego.io/docs/hertz/tutorials/basic-feature/middleware/

justlorain commented 1 year ago

Please assign me.

li-jin-gou commented 1 year ago

Please assign me.

thanks

edufriendchen commented 1 year ago

Please assign it to me