google.golang.org/grpc@v1.72.2/keepalive/keepalive.go (about)

     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  
    19  // Package keepalive defines configurable parameters for point-to-point
    20  // healthcheck.
    21  package keepalive
    22  
    23  import (
    24  	"time"
    25  )
    26  
    27  // ClientParameters is used to set keepalive parameters on the client-side.
    28  // These configure how the client will actively probe to notice when a
    29  // connection is broken and send pings so intermediaries will be aware of the
    30  // liveness of the connection. Make sure these parameters are set in
    31  // coordination with the keepalive policy on the server, as incompatible
    32  // settings can result in closing of connection.
    33  type ClientParameters struct {
    34  	// After a duration of this time if the client doesn't see any activity it
    35  	// pings the server to see if the transport is still alive.
    36  	// If set below 10s, a minimum value of 10s will be used instead.
    37  	//
    38  	// Note that gRPC servers have a default EnforcementPolicy.MinTime of 5
    39  	// minutes (which means the client shouldn't ping more frequently than every
    40  	// 5 minutes).
    41  	//
    42  	// Though not ideal, it's not a strong requirement for Time to be less than
    43  	// EnforcementPolicy.MinTime.  Time will automatically double if the server
    44  	// disconnects due to its enforcement policy.
    45  	//
    46  	// For more details, see
    47  	// https://github.com/grpc/proposal/blob/master/A8-client-side-keepalive.md
    48  	Time time.Duration
    49  	// After having pinged for keepalive check, the client waits for a duration
    50  	// of Timeout and if no activity is seen even after that the connection is
    51  	// closed.
    52  	//
    53  	// If keepalive is enabled, and this value is not explicitly set, the default
    54  	// is 20 seconds.
    55  	Timeout time.Duration
    56  	// If true, client sends keepalive pings even with no active RPCs. If false,
    57  	// when there are no active RPCs, Time and Timeout will be ignored and no
    58  	// keepalive pings will be sent.
    59  	PermitWithoutStream bool
    60  }
    61  
    62  // ServerParameters is used to set keepalive and max-age parameters on the
    63  // server-side.
    64  type ServerParameters struct {
    65  	// MaxConnectionIdle is a duration for the amount of time after which an
    66  	// idle connection would be closed by sending a GoAway. Idleness duration is
    67  	// defined since the most recent time the number of outstanding RPCs became
    68  	// zero or the connection establishment.
    69  	MaxConnectionIdle time.Duration // The current default value is infinity.
    70  	// MaxConnectionAge is a duration for the maximum amount of time a
    71  	// connection may exist before it will be closed by sending a GoAway. A
    72  	// random jitter of +/-10% will be added to MaxConnectionAge to spread out
    73  	// connection storms.
    74  	MaxConnectionAge time.Duration // The current default value is infinity.
    75  	// MaxConnectionAgeGrace is an additive period after MaxConnectionAge after
    76  	// which the connection will be forcibly closed.
    77  	MaxConnectionAgeGrace time.Duration // The current default value is infinity.
    78  	// After a duration of this time if the server doesn't see any activity it
    79  	// pings the client to see if the transport is still alive.
    80  	// If set below 1s, a minimum value of 1s will be used instead.
    81  	Time time.Duration // The current default value is 2 hours.
    82  	// After having pinged for keepalive check, the server waits for a duration
    83  	// of Timeout and if no activity is seen even after that the connection is
    84  	// closed.
    85  	Timeout time.Duration // The current default value is 20 seconds.
    86  }
    87  
    88  // EnforcementPolicy is used to set keepalive enforcement policy on the
    89  // server-side. Server will close connection with a client that violates this
    90  // policy.
    91  type EnforcementPolicy struct {
    92  	// MinTime is the minimum amount of time a client should wait before sending
    93  	// a keepalive ping.
    94  	MinTime time.Duration // The current default value is 5 minutes.
    95  	// If true, server allows keepalive pings even when there are no active
    96  	// streams(RPCs). If false, and client sends ping when there are no active
    97  	// streams, server will send GOAWAY and close the connection.
    98  	PermitWithoutStream bool // false by default.
    99  }