File tree Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Expand file tree Collapse file tree 1 file changed +10
-3
lines changed Original file line number Diff line number Diff line change @@ -225,11 +225,18 @@ type TaskCgroupEntry struct {
225
225
// GetCgroupEntries generates the contents of /proc/<pid>/cgroup as
226
226
// a TaskCgroupEntry array.
227
227
func (t * Task ) GetCgroupEntries () []TaskCgroupEntry {
228
+ // Gather cgroups with t.mu held.
228
229
t .mu .Lock ()
229
- defer t .mu .Unlock ()
230
-
231
- cgEntries := make ([]TaskCgroupEntry , 0 , len (t .cgroups ))
230
+ cgroups := make ([]Cgroup , 0 , len (t .cgroups ))
232
231
for c := range t .cgroups {
232
+ cgroups = append (cgroups , c )
233
+ }
234
+ t .mu .Unlock ()
235
+
236
+ // Don't hold t.mu here as that can lead to lock inversion with
237
+ // kernfs.ancestryRWMutex when calculating cgroup paths.
238
+ cgEntries := make ([]TaskCgroupEntry , 0 , len (cgroups ))
239
+ for _ , c := range cgroups {
233
240
ctls := c .Controllers ()
234
241
ctlNames := make ([]string , 0 , len (ctls ))
235
242
You can’t perform that action at this time.
0 commit comments