istio
40 строк · 1.5 Кб
1//go:build windows
2// +build windows
3
4/*
5Copyright 2023 The Kubernetes Authors.
6Licensed under the Apache License, Version 2.0 (the "License");
7you may not use this file except in compliance with the License.
8You may obtain a copy of the License at
9http://www.apache.org/licenses/LICENSE-2.0
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
15*/
16
17package status
18
19import (
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
31func ProbeDialer() *net.Dialer {
32dialer := &net.Dialer{
33Control: func(network, address string, c syscall.RawConn) error {
34return c.Control(func(fd uintptr) {
35syscall.SetsockoptLinger(syscall.Handle(fd), syscall.SOL_SOCKET, syscall.SO_LINGER, &syscall.Linger{Onoff: 1, Linger: 1})
36})
37},
38}
39return dialer
40}
41