keepalive.go 4.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. *
  3. * Copyright 2017, Google Inc.
  4. * All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions are
  8. * met:
  9. *
  10. * * Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * * Redistributions in binary form must reproduce the above
  13. * copyright notice, this list of conditions and the following disclaimer
  14. * in the documentation and/or other materials provided with the
  15. * distribution.
  16. * * Neither the name of Google Inc. nor the names of its
  17. * contributors may be used to endorse or promote products derived from
  18. * this software without specific prior written permission.
  19. *
  20. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  23. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  24. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  25. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  26. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  27. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  28. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  29. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  30. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  31. *
  32. */
  33. // Package keepalive defines configurable parameters for point-to-point healthcheck.
  34. package keepalive
  35. import (
  36. "time"
  37. )
  38. // ClientParameters is used to set keepalive parameters on the client-side.
  39. // These configure how the client will actively probe to notice when a connection is broken
  40. // and send pings so intermediaries will be aware of the liveness of the connection.
  41. // Make sure these parameters are set in coordination with the keepalive policy on the server,
  42. // as incompatible settings can result in closing of connection.
  43. type ClientParameters struct {
  44. // After a duration of this time if the client doesn't see any activity it pings the server to see if the transport is still alive.
  45. Time time.Duration // The current default value is infinity.
  46. // After having pinged for keepalive check, the client waits for a duration of Timeout and if no activity is seen even after that
  47. // the connection is closed.
  48. Timeout time.Duration // The current default value is 20 seconds.
  49. // If true, client runs keepalive checks even with no active RPCs.
  50. PermitWithoutStream bool // false by default.
  51. }
  52. // ServerParameters is used to set keepalive and max-age parameters on the server-side.
  53. type ServerParameters struct {
  54. // MaxConnectionIdle is a duration for the amount of time after which an idle connection would be closed by sending a GoAway.
  55. // Idleness duration is defined since the most recent time the number of outstanding RPCs became zero or the connection establishment.
  56. MaxConnectionIdle time.Duration // The current default value is infinity.
  57. // MaxConnectionAge is a duration for the maximum amount of time a connection may exist before it will be closed by sending a GoAway.
  58. // A random jitter of +/-10% will be added to MaxConnectionAge to spread out connection storms.
  59. MaxConnectionAge time.Duration // The current default value is infinity.
  60. // MaxConnectinoAgeGrace is an additive period after MaxConnectionAge after which the connection will be forcibly closed.
  61. MaxConnectionAgeGrace time.Duration // The current default value is infinity.
  62. // After a duration of this time if the server doesn't see any activity it pings the client to see if the transport is still alive.
  63. Time time.Duration // The current default value is 2 hours.
  64. // After having pinged for keepalive check, the server waits for a duration of Timeout and if no activity is seen even after that
  65. // the connection is closed.
  66. Timeout time.Duration // The current default value is 20 seconds.
  67. }
  68. // EnforcementPolicy is used to set keepalive enforcement policy on the server-side.
  69. // Server will close connection with a client that violates this policy.
  70. type EnforcementPolicy struct {
  71. // MinTime is the minimum amount of time a client should wait before sending a keepalive ping.
  72. MinTime time.Duration // The current default value is 5 minutes.
  73. // If true, server expects keepalive pings even when there are no active streams(RPCs).
  74. PermitWithoutStream bool // false by default.
  75. }