improve SFTP loop detection

This commit is contained in:
Nicola Murino
2021-04-01 18:53:48 +02:00
parent 3bfd7e4d17
commit 2f56375121
14 changed files with 353 additions and 75 deletions

View File

@@ -474,9 +474,10 @@ func EncodeTLSCertToPem(tlsCert *x509.Certificate) (string, error) {
return string(pem.EncodeToMemory(&publicKeyBlock)), nil
}
// CheckTCP4Port quits the app if bind to the given IPv4 port.
// CheckTCP4Port quits the app if bind on the given IPv4 port fails.
// This is a ugly hack to avoid to bind on an already used port.
// It is required on Windows only.
// It is required on Windows only. Upstream does not consider this
// behaviour a bug:
// https://github.com/golang/go/issues/45150
func CheckTCP4Port(port int) {
if runtime.GOOS != osWindows {
@@ -484,8 +485,8 @@ func CheckTCP4Port(port int) {
}
listener, err := net.Listen("tcp4", fmt.Sprintf(":%d", port))
if err != nil {
logger.ErrorToConsole("unable to bind tcp4 address: %v", err)
logger.Error(logSender, "", "unable to bind tcp4 address: %v", err)
logger.ErrorToConsole("unable to bind on tcp4 address: %v", err)
logger.Error(logSender, "", "unable to bind on tcp4 address: %v", err)
os.Exit(1)
}
listener.Close()