Skip to content

Commit

Permalink
Experiment: enable race detector in integration test
Browse files Browse the repository at this point in the history
  • Loading branch information
enfein committed Feb 4, 2024
1 parent 78857bc commit f13531e
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 13 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -324,8 +324,8 @@ rpm-server-arm64: server-linux-arm64
test-binary:
CGO_ENABLED=0 go build -ldflags="-X 'github.com/enfein/mieru/pkg/log.LogPrefix=C'" -o mieru cmd/mieru/mieru.go
CGO_ENABLED=0 go build -ldflags="-X 'github.com/enfein/mieru/pkg/log.LogPrefix=S'" -o mita cmd/mita/mita.go
CGO_ENABLED=0 go build -ldflags="-X 'github.com/enfein/mieru/pkg/log.LogPrefix=C2'" -o mieru2 cmd/mieru/mieru.go
CGO_ENABLED=0 go build -ldflags="-X 'github.com/enfein/mieru/pkg/log.LogPrefix=S2'" -o mita2 cmd/mita/mita.go
CGO_ENABLED=1 go build -race -ldflags="-X 'github.com/enfein/mieru/pkg/log.LogPrefix=C2'" -o mieru2 cmd/mieru/mieru.go
CGO_ENABLED=1 go build -race -ldflags="-X 'github.com/enfein/mieru/pkg/log.LogPrefix=S2'" -o mita2 cmd/mita/mita.go
CGO_ENABLED=0 go build test/cmd/httpserver/httpserver.go
CGO_ENABLED=0 go build test/cmd/sockshttpclient/sockshttpclient.go
CGO_ENABLED=0 go build test/cmd/socksudpclient/socksudpclient.go
Expand Down
29 changes: 26 additions & 3 deletions pkg/appctl/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ func (s *serverLifecycleService) Start(ctx context.Context, req *pb.Empty) (*pb.
if err != nil {
return &pb.Empty{}, fmt.Errorf("LoadServerConfig() failed: %w", err)
}
if err = ValidateFullServerConfig(config); err != nil {
return &pb.Empty{}, fmt.Errorf("ValidateFullServerConfig() failed: %w", err)
}
loggingLevel := config.GetLoggingLevel().String()
if loggingLevel != pb.LoggingLevel_DEFAULT.String() {
log.SetLevel(loggingLevel)
}
if err = ValidateFullServerConfig(config); err != nil {
return &pb.Empty{}, fmt.Errorf("ValidateFullServerConfig() failed: %w", err)
}
if socks5ServerRef.Load() != nil {
log.Infof("socks5 server already exist")
return &pb.Empty{}, nil
Expand Down Expand Up @@ -196,6 +196,29 @@ func (s *serverLifecycleService) Stop(ctx context.Context, req *pb.Empty) (*pb.E
return &pb.Empty{}, nil
}

func (s *serverLifecycleService) Reload(ctx context.Context, req *pb.Empty) (*pb.Empty, error) {
log.Infof("received start request from RPC caller")
config, err := LoadServerConfig()
if err != nil {
return &pb.Empty{}, fmt.Errorf("LoadServerConfig() failed: %w", err)
}
if err = ValidateFullServerConfig(config); err != nil {
return &pb.Empty{}, fmt.Errorf("ValidateFullServerConfig() failed: %w", err)
}
mux := serverMuxRef.Load()
// Adjust portBindings.
// Adjust users.
if mux != nil {
mux.SetServerUsers(UserListToMap(config.GetUsers()))
}
// Adjust loggingLevel.
loggingLevel := config.GetLoggingLevel().String()
if loggingLevel != pb.LoggingLevel_DEFAULT.String() {
log.SetLevel(loggingLevel)
}
return &pb.Empty{}, nil
}

func (s *serverLifecycleService) Exit(ctx context.Context, req *pb.Empty) (*pb.Empty, error) {
SetAppStatus(pb.AppStatus_STOPPING)
log.Infof("received exit request from RPC caller")
Expand Down
12 changes: 8 additions & 4 deletions pkg/protocolv2/segment.go
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (t *segmentTree) DeleteMin() (*segment, bool) {
t.mu.Lock()
defer t.mu.Unlock()

if t.Len() == 0 {
if t.tr.Len() == 0 {
return nil, false
}
seg, ok := t.tr.DeleteMin()
Expand All @@ -251,7 +251,7 @@ func (t *segmentTree) DeleteMin() (*segment, bool) {
panic("segmentTree.DeleteMin() return nil")
}
t.notFull.Broadcast()
if t.Len() > 0 {
if t.tr.Len() > 0 {
t.notifyNotEmpty()
} else {
t.notifyEmpty()
Expand All @@ -266,7 +266,7 @@ func (t *segmentTree) DeleteMinIf(si segmentIterator) (*segment, bool) {
t.mu.Lock()
defer t.mu.Unlock()

if t.Len() == 0 {
if t.tr.Len() == 0 {
return nil, false
}
seg, ok := t.tr.Min()
Expand All @@ -287,7 +287,7 @@ func (t *segmentTree) DeleteMinIf(si segmentIterator) (*segment, bool) {
}
t.notFull.Broadcast()
}
if t.Len() > 0 {
if t.tr.Len() > 0 {
t.notifyNotEmpty()
} else {
t.notifyEmpty()
Expand Down Expand Up @@ -337,11 +337,15 @@ func (t *segmentTree) MaxSeq() (uint32, error) {

// Len returns the current size of the tree.
func (t *segmentTree) Len() int {
t.mu.Lock()
defer t.mu.Unlock()
return t.tr.Len()
}

// Remaining returns the remaining space of the tree before it is full.
func (t *segmentTree) Remaining() int {
t.mu.Lock()
defer t.mu.Unlock()
return t.cap - t.tr.Len()
}

Expand Down
12 changes: 8 additions & 4 deletions pkg/protocolv2/underlay_udp.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,16 @@ func (u *UDPUnderlay) RunEventLoop(ctx context.Context) error {
// Close idle sessions.
u.sessionMap.Range(func(k, v any) bool {
session := v.(*Session)
select {
case <-session.done:
log.Debugf("Found closed %v", session)
if err := u.RemoveSession(session); err != nil {
log.Debugf("%v RemoveSession() failed: %v", u, err)
}
default:
}
if time.Since(session.lastRXTime) > idleSessionTimeout {
log.Debugf("Found idle %v", session)
if err := session.Close(); err != nil && !stderror.IsEOF(err) && !stderror.IsClosed(err) {
log.Debugf("%v Close() failed: %v", session, err)
}
session.wg.Wait()
if err := u.RemoveSession(session); err != nil {
log.Debugf("%v RemoveSession() failed: %v", u, err)
}
Expand Down

0 comments on commit f13531e

Please sign in to comment.