From 2156fbc01ee1c6a90d026ade835e27390c70c8b3 Mon Sep 17 00:00:00 2001 From: Winni Neessen Date: Mon, 11 Nov 2024 18:51:14 +0100 Subject: [PATCH] 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. --- smtp/smtp_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/smtp/smtp_test.go b/smtp/smtp_test.go index 9ac6118..ee1ae5a 100644 --- a/smtp/smtp_test.go +++ b/smtp/smtp_test.go @@ -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() } } }