Skip to content

Commit

Permalink
Fix data race error in 'networking_test' package
Browse files Browse the repository at this point in the history
Implement 'io.Stringer' for 'Session' struct.
Data race happens because 'clientHandler' mock in 'TestSessionTimeoutOnHandshake' test
reads 'Session' structure at the same time as 'clientSession.Close' call.
  • Loading branch information
nickeskov committed Nov 28, 2024
1 parent 7bab250 commit df01e60
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/networking/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"context"
"encoding/base64"
"errors"
"fmt"
"io"
"log/slog"
"net"
Expand Down Expand Up @@ -85,6 +86,10 @@ func newSession(ctx context.Context, config *Config, conn io.ReadWriteCloser, tp
return s, nil
}

func (s *Session) String() string {
return fmt.Sprintf("Session{local=%s,remote=%s}", s.LocalAddr(), s.RemoteAddr())
}

// LocalAddr returns the local network address.
func (s *Session) LocalAddr() net.Addr {
if a, ok := s.conn.(addressable); ok {
Expand Down

0 comments on commit df01e60

Please sign in to comment.