-
Notifications
You must be signed in to change notification settings - Fork 203
[full-ci] Fix panic while traversing the service list #11390
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using a RWMutex
might be better, but I don't think we expect too much concurrency to be really useful. I mean, we probably need to deal with one goroutine for the startup and another one for the list command, so only 2 goroutines to handle.
ocis/pkg/runtime/service/service.go
Outdated
@@ -486,6 +488,8 @@ func (s *Service) List(_ struct{}, reply *string) error { | |||
table := tablewriter.NewWriter(tableString) | |||
table.SetHeader([]string{"Service"}) | |||
|
|||
s.mu.Lock() | |||
defer s.mu.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
something to consider is to move the unlock right after the for
so the mutex is locked the least amount of time. In this case it isn't a big deal because the function shouldn't take a lot of time to complete, so the mutex should be locked for a little time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
ocis/pkg/runtime/service/service.go
Outdated
@@ -519,6 +523,8 @@ func trapShutdownCtx(s *Service, srv *http.Server, ctx context.Context) { | |||
s.Log.Info().Msg("tcp listener shutdown") | |||
}() | |||
|
|||
s.mu.Lock() | |||
defer s.mu.Unlock() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better move the unlock after the for
loop, otherwise we'll need to wait until all the services have shutdown of we reach the _defaultInterruptTimeoutDuration
timeout; it will take too much time to unlock the mutex and it could block other goroutines for a long time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated
|
[full-ci] Fix panic while traversing the service list
Description
Fix panic while traversing the service list.
Related Issue
Motivation and Context
How Has This Been Tested?
Screenshots (if appropriate):
Types of changes
Checklist: