mirror of
https://github.com/wneessen/go-mail.git
synced 2024-11-15 02:12:55 +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"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
"strings"
|
"strings"
|
||||||
|
"sync"
|
||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
"testing"
|
"testing"
|
||||||
"time"
|
"time"
|
||||||
|
@ -3592,6 +3593,7 @@ type serverProps struct {
|
||||||
SSLListener bool
|
SSLListener bool
|
||||||
TestSCRAM bool
|
TestSCRAM bool
|
||||||
VRFYUserUnknown bool
|
VRFYUserUnknown bool
|
||||||
|
mutex sync.Mutex
|
||||||
}
|
}
|
||||||
|
|
||||||
// simpleSMTPServer starts a simple TCP server that resonds to SMTP commands.
|
// 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)
|
return fmt.Errorf("unable to accept connection: %w", err)
|
||||||
}
|
}
|
||||||
|
props.mutex.Lock()
|
||||||
handleTestServerConnection(connection, t, props)
|
handleTestServerConnection(connection, t, props)
|
||||||
|
props.mutex.Unlock()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue