Fix #277 race condition in ProcessGroup.ProxyRequest when swap=true

This commit is contained in:
Benson Wong
2025-08-28 21:38:36 -07:00
parent 57803fd3aa
commit 52b329f7bc
3 changed files with 44 additions and 17 deletions

View File

@@ -60,10 +60,20 @@ func (pg *ProcessGroup) ProxyRequest(modelID string, writer http.ResponseWriter,
if pg.swap {
pg.Lock()
if pg.lastUsedProcess != modelID {
// is there something already running?
if pg.lastUsedProcess != "" {
pg.processes[pg.lastUsedProcess].Stop()
}
// wait for the request to the new model to be fully handled
// and prevent race conditions see issue #277
pg.processes[modelID].ProxyRequest(writer, request)
pg.lastUsedProcess = modelID
// short circuit and exit
pg.Unlock()
return nil
}
pg.Unlock()
}