Add mutex lock to handle concurrent SMTP test server connections

Introduced a mutex to the SMTP test server properties to ensure thread-safe access when handling connections. This prevents race conditions and improves the reliability of the test server under concurrent load.
This commit is contained in:
Winni Neessen 2024-11-11 18:51:14 +01:00
parent 61353d51e5
commit 2156fbc01e
Signed by: wneessen
GPG key ID: 385AC9889632126E

View file

@ -31,6 +31,7 @@ import (
"net"
"os"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
@ -3592,6 +3593,7 @@ type serverProps struct {
SSLListener bool
TestSCRAM bool
VRFYUserUnknown bool
mutex sync.Mutex
}
// simpleSMTPServer starts a simple TCP server that resonds to SMTP commands.
@ -3643,7 +3645,9 @@ func simpleSMTPServer(ctx context.Context, t *testing.T, props *serverProps) err
}
return fmt.Errorf("unable to accept connection: %w", err)
}
props.mutex.Lock()
handleTestServerConnection(connection, t, props)
props.mutex.Unlock()
}
}
}