Skip to content

Commit

Permalink
Add mutex lock to handle concurrent SMTP test server connections
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
wneessen committed Nov 11, 2024
1 parent 61353d5 commit 2156fbc
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions smtp/smtp_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"net"
"os"
"strings"
"sync"
"sync/atomic"
"testing"
"time"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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()
}
}
}
Expand Down

0 comments on commit 2156fbc

Please sign in to comment.