Skip to content

Commit 98cb312

Browse files
authored
fix: container mount path corruption due to concurrent sort in info lookup (#2164)
1 parent 4f7dbf8 commit 98cb312

File tree

3 files changed

+14
-7
lines changed

3 files changed

+14
-7
lines changed

Diff for: pkg/helper/docker_center.go

+7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"path/filepath"
2121
"regexp"
2222
"runtime"
23+
"sort"
2324
"strings"
2425
"sync"
2526
"sync/atomic"
@@ -623,6 +624,12 @@ func (dc *DockerCenter) CreateInfoDetail(info types.ContainerJSON, envConfigPref
623624
info.Mounts[i].Source = filepath.Clean(info.Mounts[i].Source)
624625
info.Mounts[i].Destination = filepath.Clean(info.Mounts[i].Destination)
625626
}
627+
sortMounts := func(mounts []types.MountPoint) {
628+
sort.Slice(mounts, func(i, j int) bool {
629+
return mounts[i].Source < mounts[j].Source
630+
})
631+
}
632+
sortMounts(info.Mounts)
626633
did := &DockerInfoDetail{
627634
StdoutPath: info.LogPath,
628635
ContainerInfo: info,

Diff for: pkg/helper/docker_center_file_discover.go

+7
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import (
2121
"io/fs"
2222
"os"
2323
"path/filepath"
24+
"sort"
2425
"strconv"
2526
"strings"
2627
"sync"
@@ -143,6 +144,12 @@ func staticContainerInfoToStandard(staticInfo *staticContainerInfo, stat fs.File
143144
Driver: mount.Driver,
144145
})
145146
}
147+
sortMounts := func(mounts []types.MountPoint) {
148+
sort.Slice(mounts, func(i, j int) bool {
149+
return mounts[i].Source < mounts[j].Source
150+
})
151+
}
152+
sortMounts(dockerContainer.Mounts)
146153
return dockerContainer
147154
}
148155

Diff for: plugins/input/docker/logmeta/metric_container_info.go

-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import (
2424
"path/filepath"
2525
"reflect"
2626
"regexp"
27-
"sort"
2827
"strings"
2928
"time"
3029

@@ -316,12 +315,6 @@ func (idf *InputDockerFile) updateMapping(info *helper.DockerInfoDetail, allCmd
316315
}
317316
}
318317

319-
sortMounts := func(mounts []types.MountPoint) {
320-
sort.Slice(mounts, func(i, j int) bool {
321-
return mounts[i].Source < mounts[j].Source
322-
})
323-
}
324-
sortMounts(mounts)
325318
// 判断mounts
326319
if !changed {
327320
if val, ok := idf.lastContainerInfoCache[id]; ok && !reflect.DeepEqual(val.Mounts, mounts) {

0 commit comments

Comments
 (0)