Skip to content

Commit b752462

Browse files
committed
Stop locking container exec store while starting
The daemon.containerd.Exec call does not access or mutate the container's ExecCommands store in any way, and locking the exec config is sufficient to synchronize with the event-processing loop. Locking the ExecCommands store while starting the exec process only serves to block unrelated operations on the container for an extended period of time. Convert the Store struct's mutex to an unexported field to prevent this from regressing in the future. Signed-off-by: Cory Snider <[email protected]>
1 parent ce550fa commit b752462

2 files changed

Lines changed: 11 additions & 14 deletions

File tree

daemon/exec.go

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -276,18 +276,15 @@ func (daemon *Daemon) ContainerExecStart(ctx context.Context, name string, optio
276276

277277
// Synchronize with libcontainerd event loop
278278
ec.Lock()
279-
c.ExecCommands.Lock()
280279
systemPid, err := daemon.containerd.Exec(ctx, c.ID, ec.ID, p, cStdin != nil, ec.InitializeStdio)
281280
// the exec context should be ready, or error happened.
282281
// close the chan to notify readiness
283282
close(ec.Started)
284283
if err != nil {
285-
c.ExecCommands.Unlock()
286284
ec.Unlock()
287285
return translateContainerdStartErr(ec.Entrypoint, ec.SetExitCode, err)
288286
}
289287
ec.Pid = systemPid
290-
c.ExecCommands.Unlock()
291288
ec.Unlock()
292289

293290
select {

daemon/exec/exec.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ func (c *Config) SetExitCode(code int) {
9393
// Store keeps track of the exec configurations.
9494
type Store struct {
9595
byID map[string]*Config
96-
sync.RWMutex
96+
mu sync.RWMutex
9797
}
9898

9999
// NewStore initializes a new exec store.
@@ -105,44 +105,44 @@ func NewStore() *Store {
105105

106106
// Commands returns the exec configurations in the store.
107107
func (e *Store) Commands() map[string]*Config {
108-
e.RLock()
108+
e.mu.RLock()
109109
byID := make(map[string]*Config, len(e.byID))
110110
for id, config := range e.byID {
111111
byID[id] = config
112112
}
113-
e.RUnlock()
113+
e.mu.RUnlock()
114114
return byID
115115
}
116116

117117
// Add adds a new exec configuration to the store.
118118
func (e *Store) Add(id string, Config *Config) {
119-
e.Lock()
119+
e.mu.Lock()
120120
e.byID[id] = Config
121-
e.Unlock()
121+
e.mu.Unlock()
122122
}
123123

124124
// Get returns an exec configuration by its id.
125125
func (e *Store) Get(id string) *Config {
126-
e.RLock()
126+
e.mu.RLock()
127127
res := e.byID[id]
128-
e.RUnlock()
128+
e.mu.RUnlock()
129129
return res
130130
}
131131

132132
// Delete removes an exec configuration from the store.
133133
func (e *Store) Delete(id string, pid int) {
134-
e.Lock()
134+
e.mu.Lock()
135135
delete(e.byID, id)
136-
e.Unlock()
136+
e.mu.Unlock()
137137
}
138138

139139
// List returns the list of exec ids in the store.
140140
func (e *Store) List() []string {
141141
var IDs []string
142-
e.RLock()
142+
e.mu.RLock()
143143
for id := range e.byID {
144144
IDs = append(IDs, id)
145145
}
146-
e.RUnlock()
146+
e.mu.RUnlock()
147147
return IDs
148148
}

0 commit comments

Comments
 (0)