You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

keepalive.md 1.7 KiB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. # Keepalive
  2. gRPC sends http2 pings on the transport to detect if the connection is down. If
  3. the ping is not acknowledged by the other side within a certain period, the
  4. connection will be close. Note that pings are only necessary when there's no
  5. activity on the connection.
  6. For how to configure keepalive, see
  7. https://godoc.org/google.golang.org/grpc/keepalive for the options.
  8. ## What should I set?
  9. It should be sufficient for most users to set [client
  10. parameters](https://godoc.org/google.golang.org/grpc/keepalive) as a [dial
  11. option](https://godoc.org/google.golang.org/grpc#WithKeepaliveParams).
  12. ## What will happen?
  13. (The behavior described here is specific for gRPC-go, it might be slightly
  14. different in other languages.)
  15. When there's no activity on a connection (note that an ongoing stream results in
  16. __no activity__ when there's no message being sent), after `Time`, a ping will
  17. be sent by the client and the server will send a ping ack when it gets the ping.
  18. Client will wait for `Timeout`, and check if there's any activity on the
  19. connection during this period (a ping ack is an activity).
  20. ## What about server side?
  21. Server has similar `Time` and `Timeout` settings as client. Server can also
  22. configure connection max-age. See [server
  23. parameters](https://godoc.org/google.golang.org/grpc/keepalive#ServerParameters)
  24. for details.
  25. ### Enforcement policy
  26. [Enforcement
  27. policy](https://godoc.org/google.golang.org/grpc/keepalive#ServerParameters) is
  28. a special setting on server side to protect server from malicious or misbehaving
  29. clients.
  30. Server sends GOAWAY with ENHANCE_YOUR_CALM and close the connection when bad
  31. behaviors are detected:
  32. - Client sends too frequent pings
  33. - Client sends pings when there's no stream and this is disallowed by server
  34. config