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