...

Source file src/k8s.io/kubernetes/pkg/probe/dialer_others.go

Documentation: k8s.io/kubernetes/pkg/probe

     1  //go:build !windows
     2  // +build !windows
     3  
     4  /*
     5  Copyright 2023 The Kubernetes Authors.
     6  
     7  Licensed under the Apache License, Version 2.0 (the "License");
     8  you may not use this file except in compliance with the License.
     9  You may obtain a copy of the License at
    10  
    11      http://www.apache.org/licenses/LICENSE-2.0
    12  
    13  Unless required by applicable law or agreed to in writing, software
    14  distributed under the License is distributed on an "AS IS" BASIS,
    15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    16  See the License for the specific language governing permissions and
    17  limitations under the License.
    18  */
    19  
    20  package probe
    21  
    22  import (
    23  	"net"
    24  	"syscall"
    25  )
    26  
    27  // ProbeDialer returns a dialer optimized for probes to avoid lingering sockets on TIME-WAIT state.
    28  // The dialer reduces the TIME-WAIT period to 1 seconds instead of the OS default of 60 seconds.
    29  // Using 1 second instead of 0 because SO_LINGER socket option to 0 causes pending data to be
    30  // discarded and the connection to be aborted with an RST rather than for the pending data to be
    31  // transmitted and the connection closed cleanly with a FIN.
    32  // Ref: https://issues.k8s.io/89898
    33  func ProbeDialer() *net.Dialer {
    34  	dialer := &net.Dialer{
    35  		Control: func(network, address string, c syscall.RawConn) error {
    36  			return c.Control(func(fd uintptr) {
    37  				syscall.SetsockoptLinger(int(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, &syscall.Linger{Onoff: 1, Linger: 1})
    38  			})
    39  		},
    40  	}
    41  	return dialer
    42  }
    43  

View as plain text