diff --git a/internal/engine/experiment/smtp/smtp.go b/internal/engine/experiment/smtp/smtp.go index a0d38ac..09d3484 100644 --- a/internal/engine/experiment/smtp/smtp.go +++ b/internal/engine/experiment/smtp/smtp.go @@ -133,12 +133,8 @@ type SMTPRunner struct { func (r SMTPRunner) smtp_error(err error) { key := net.JoinHostPort(r.addr, r.port) - errors, exists := r.tk.SMTPErrors[key] - if exists { - r.tk.SMTPErrors[key] = append(errors, tracex.NewFailure(err)) - } else { - r.tk.SMTPErrors[key] = []*string{tracex.NewFailure(err)} - } + // Key is initialized in conn() no need to check here + r.tk.SMTPErrors[key] = append(r.tk.SMTPErrors[key], tracex.NewFailure(err)) } func (r SMTPRunner) resolve(host string) ([]string, bool) { @@ -156,7 +152,13 @@ func (r SMTPRunner) resolve(host string) ([]string, bool) { } func (r SMTPRunner) conn(addr string) (net.Conn, bool) { + // Initialize addr field and corresponding errors in TestKeys r.addr = addr + if r.tk.SMTPErrors == nil { + r.tk.SMTPErrors = make(map[string][]*string) + } + r.tk.SMTPErrors[net.JoinHostPort(addr, r.port)] = []*string{} + dialer := r.trace.NewDialerWithoutResolver(r.logger) conn, err := dialer.DialContext(r.ctx, "tcp", net.JoinHostPort(r.addr, r.port)) r.tk.TCPConnect = append(r.tk.TCPConnect, r.trace.TCPConnects()...) @@ -243,8 +245,6 @@ func (m Measurer) Run( } tk := new(TestKeys) - // TODO: make it so we don't forget it - tk.SMTPErrors = make(map[string][]*string) measurement.TestKeys = tk ctx, cancel := context.WithTimeout(ctx, 60*time.Second)