diff --git a/docs/user_guide/server/overview.md b/docs/user_guide/server/overview.md index 5dd4ffe..eac2b36 100644 --- a/docs/user_guide/server/overview.md +++ b/docs/user_guide/server/overview.md @@ -268,6 +268,19 @@ tRPC-Go provides three timeout mechanisms for RPC calls: link timeout, message t This feature requires protocol support (the protocol needs to carry timeout metadata downstream). The tRPC protocol, generic HTTP RPC protocol all support timeout control. +## Idle Timeout + +The server has a default idle timeout of 60 seconds to prevent excessive idle connections from consuming server-side resources. This value can be modified through the `idletimeout` setting in the framework configuration: + +```yaml +server: + service: + - name: trpc.server.service.Method + network: tcp + protocol: trpc + idletime: 60000 # The unit is milliseconds. Setting it to -1 means there is no idle timeout (setting it to 0 will still default to the 60s by the framework) +``` + ## Link transmission The tRPC-Go framework provides a mechanism for passing fields between the client and server and passing them down the entire call chain. For the mechanism and usage of link transmission, please refer to [tRPC-Go Link Transmission](/docs/user_guide/metadata_transmission.md). diff --git a/docs/user_guide/server/overview.zh_CN.md b/docs/user_guide/server/overview.zh_CN.md index 640697b..7c74efd 100644 --- a/docs/user_guide/server/overview.zh_CN.md +++ b/docs/user_guide/server/overview.zh_CN.md @@ -266,7 +266,20 @@ tRPC-Go 从设计之初就考虑了框架的易测性,在通过 pb 生成桩 tRPC-Go 为 RPC 调用提供了 3 种超时机制控制:链路超时,消息超时和调用超时。关于这 3 种超时机制的原理介绍和相关配置,请参考 [tRPC-Go 超时控制](/docs/user_guide/timeout_control.zh_CN.md)。 -此功能需要协议的支持(协议需要携带 timeout 元数据到下游),tRPC 协议,泛 HTTP RPC 协议均支持超时控制功能。其 +此功能需要协议的支持(协议需要携带 timeout 元数据到下游),tRPC 协议,泛 HTTP RPC 协议均支持超时控制功能。 + +## 空闲超时 + +服务默认存在一个 60s 的空闲超时时间,以防止过多空闲连接消耗服务侧的资源,这个值可以通过框架配置中的 `idletimeout` 来进行修改: + +```yaml +server: + service: + - name: trpc.server.service.Method + network: tcp + protocol: trpc + idletime: 60000 # 单位是毫秒, 设置为 -1 的时候表示没有空闲超时(这里设置为 0 时框架仍会自动转为默认的 60s) +``` ## 链路透传 diff --git a/http/transport_test.go b/http/transport_test.go index 4659d05..3c51c00 100644 --- a/http/transport_test.go +++ b/http/transport_test.go @@ -809,6 +809,9 @@ func TestCheckRedirect(t *testing.T) { return nil } thttp.DefaultClientTransport.(*thttp.ClientTransport).CheckRedirect = checkRedirect + defer func() { + thttp.DefaultClientTransport.(*thttp.ClientTransport).CheckRedirect = nil + }() proxy := thttp.NewClientProxy("trpc.test.helloworld.Greeter", client.WithTarget("ip://"+ln.Addr().String()), client.WithSerializationType(codec.SerializationTypeNoop), diff --git a/pool/connpool/checker_unix_test.go b/pool/connpool/checker_unix_test.go index 6f303a6..5ec677c 100644 --- a/pool/connpool/checker_unix_test.go +++ b/pool/connpool/checker_unix_test.go @@ -53,7 +53,7 @@ func TestRemoteEOF(t *testing.T) { require.Nil(t, pc.Close()) } -func TestUnexceptedRead(t *testing.T) { +func TestUnexpectedRead(t *testing.T) { var s server require.Nil(t, s.init())