Skip to content

Commit 6a695dc

Browse files
authored
Merge pull request #116 from doringeman/lock
fix: switch to a RWMutex for synchronizing the router rebuild
2 parents 0c1a6b7 + 5fa2bee commit 6a695dc

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

pkg/inference/models/manager.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ type Manager struct {
4141
// registryClient is the client for model registry.
4242
registryClient *registry.Client
4343
// lock is used to synchronize access to the models manager's router.
44-
lock sync.Mutex
44+
lock sync.RWMutex
4545
}
4646

4747
type ClientConfig struct {
@@ -542,8 +542,8 @@ func (m *Manager) GetDiskUsage() (int64, error, int) {
542542

543543
// ServeHTTP implement net/http.Handler.ServeHTTP.
544544
func (m *Manager) ServeHTTP(w http.ResponseWriter, r *http.Request) {
545-
m.lock.Lock()
546-
defer m.lock.Unlock()
545+
m.lock.RLock()
546+
defer m.lock.RUnlock()
547547
m.router.ServeHTTP(w, r)
548548
}
549549

pkg/inference/scheduling/scheduler.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ type Scheduler struct {
4343
// openAIRecorder is used to record OpenAI API inference requests and responses.
4444
openAIRecorder *metrics.OpenAIRecorder
4545
// lock is used to synchronize access to the scheduler's router.
46-
lock sync.Mutex
46+
lock sync.RWMutex
4747
}
4848

4949
// NewScheduler creates a new inference scheduler.
@@ -510,7 +510,7 @@ func parseBackendMode(mode string) inference.BackendMode {
510510

511511
// ServeHTTP implements net/http.Handler.ServeHTTP.
512512
func (s *Scheduler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
513-
s.lock.Lock()
514-
defer s.lock.Unlock()
513+
s.lock.RLock()
514+
defer s.lock.RUnlock()
515515
s.router.ServeHTTP(w, r)
516516
}

0 commit comments

Comments
 (0)