keepalive.go 3.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /*
  2. *
  3. * Copyright 2017 gRPC authors.
  4. *
  5. * Licensed under the Apache License, Version 2.0 (the "License");
  6. * you may not use this file except in compliance with the License.
  7. * You may obtain a copy of the License at
  8. *
  9. * http://www.apache.org/licenses/LICENSE-2.0
  10. *
  11. * Unless required by applicable law or agreed to in writing, software
  12. * distributed under the License is distributed on an "AS IS" BASIS,
  13. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  14. * See the License for the specific language governing permissions and
  15. * limitations under the License.
  16. *
  17. */
  18. // Package keepalive defines configurable parameters for point-to-point
  19. // healthcheck.
  20. package keepalive
  21. import (
  22. "time"
  23. )
  24. // ClientParameters is used to set keepalive parameters on the client-side.
  25. // These configure how the client will actively probe to notice when a
  26. // connection is broken and send pings so intermediaries will be aware of the
  27. // liveness of the connection. Make sure these parameters are set in
  28. // coordination with the keepalive policy on the server, as incompatible
  29. // settings can result in closing of connection.
  30. type ClientParameters struct {
  31. // After a duration of this time if the client doesn't see any activity it
  32. // pings the server to see if the transport is still alive.
  33. Time time.Duration // The current default value is infinity.
  34. // After having pinged for keepalive check, the client waits for a duration
  35. // of Timeout and if no activity is seen even after that the connection is
  36. // closed.
  37. Timeout time.Duration // The current default value is 20 seconds.
  38. // If true, client sends keepalive pings even with no active RPCs. If false,
  39. // when there are no active RPCs, Time and Timeout will be ignored and no
  40. // keepalive pings will be sent.
  41. PermitWithoutStream bool // false by default.
  42. }
  43. // ServerParameters is used to set keepalive and max-age parameters on the
  44. // server-side.
  45. type ServerParameters struct {
  46. // MaxConnectionIdle is a duration for the amount of time after which an
  47. // idle connection would be closed by sending a GoAway. Idleness duration is
  48. // defined since the most recent time the number of outstanding RPCs became
  49. // zero or the connection establishment.
  50. MaxConnectionIdle time.Duration // The current default value is infinity.
  51. // MaxConnectionAge is a duration for the maximum amount of time a
  52. // connection may exist before it will be closed by sending a GoAway. A
  53. // random jitter of +/-10% will be added to MaxConnectionAge to spread out
  54. // connection storms.
  55. MaxConnectionAge time.Duration // The current default value is infinity.
  56. // MaxConnectinoAgeGrace is an additive period after MaxConnectionAge after
  57. // which the connection will be forcibly closed.
  58. MaxConnectionAgeGrace time.Duration // The current default value is infinity.
  59. // After a duration of this time if the server doesn't see any activity it
  60. // pings the client to see if the transport is still alive.
  61. Time time.Duration // The current default value is 2 hours.
  62. // After having pinged for keepalive check, the server waits for a duration
  63. // of Timeout and if no activity is seen even after that the connection is
  64. // closed.
  65. Timeout time.Duration // The current default value is 20 seconds.
  66. }
  67. // EnforcementPolicy is used to set keepalive enforcement policy on the
  68. // server-side. Server will close connection with a client that violates this
  69. // policy.
  70. type EnforcementPolicy struct {
  71. // MinTime is the minimum amount of time a client should wait before sending
  72. // a keepalive ping.
  73. MinTime time.Duration // The current default value is 5 minutes.
  74. // If true, server allows keepalive pings even when there are no active
  75. // streams(RPCs). If false, and client sends ping when there are no active
  76. // streams, server will send GOAWAY and close the connection.
  77. PermitWithoutStream bool // false by default.
  78. }