mirror of
https://github.com/wneessen/go-mail.git
synced 2024-12-22 18:50:37 +01:00
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:
parent
61353d51e5
commit
2156fbc01e
1 changed files with 4 additions and 0 deletions
|
@ -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()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue