Skip to content

Commit 31a097a

Browse files
fix: managed containers return after inference completed (#301)
* fix managed container return to start watchContainer monitoring to enabled returning container when inference is completed
1 parent d11b114 commit 31a097a

File tree

1 file changed

+11
-7
lines changed

1 file changed

+11
-7
lines changed

worker/docker.go

+11-7
Original file line numberDiff line numberDiff line change
@@ -170,24 +170,28 @@ func (m *DockerManager) Stop(ctx context.Context) error {
170170
func (m *DockerManager) Borrow(ctx context.Context, pipeline, modelID string) (*RunnerContainer, error) {
171171
m.mu.Lock()
172172
defer m.mu.Unlock()
173+
var rc *RunnerContainer
174+
var err error
173175

174176
for _, runner := range m.containers {
175177
if runner.Pipeline == pipeline && runner.ModelID == modelID {
176-
delete(m.containers, runner.Name)
177-
return runner, nil
178+
rc = runner
179+
break
178180
}
179181
}
180182

181183
// The container does not exist so try to create it
182-
var err error
183-
// TODO: Optimization flags for dynamically loaded (borrowed) containers are not currently supported due to startup delays.
184-
rc, err := m.createContainer(ctx, pipeline, modelID, false, map[string]EnvValue{})
185-
if err != nil {
186-
return nil, err
184+
if rc == nil {
185+
// TODO: Optimization flags for dynamically loaded (borrowed) containers are not currently supported due to startup delays.
186+
rc, err = m.createContainer(ctx, pipeline, modelID, false, map[string]EnvValue{})
187+
if err != nil {
188+
return nil, err
189+
}
187190
}
188191

189192
// Remove container so it is unavailable until Return() is called
190193
delete(m.containers, rc.Name)
194+
// watch container to return when request completed
191195
go m.watchContainer(rc, ctx)
192196

193197
return rc, nil

0 commit comments

Comments
 (0)