keepaliveParams 返回 grpc.WithKeepaliveParams 选项。 PermitWithoutStream=true 让 client 在没有 active stream 时也能维持 ping, 与 server 的 EnforcementPolicy.PermitWithoutStream=true 配合,配合 reaper 实现死连接快速发现。
(cfg Config)
| 225 | // 与 server 的 EnforcementPolicy.PermitWithoutStream=true 配合,配合 reaper |
| 226 | // 实现死连接快速发现。 |
| 227 | func keepaliveParams(cfg Config) grpc.DialOption { |
| 228 | return grpc.WithKeepaliveParams(keepalive.ClientParameters{ |
| 229 | Time: cfg.KeepaliveTime, |
| 230 | Timeout: cfg.KeepaliveTimeout, |
| 231 | PermitWithoutStream: true, |
| 232 | }) |
| 233 | } |