Skip to content

Commit 9f6eb58

Browse files
authored
fix report concurrency crash when helm-diff used as a library (#256)
the Manifests codepath was calling setupReportFormat on a mutable global map, which means that calling Manifests from different gothreads is an error, and can produce a panic with this (abbreviated) traceback: fatal error: concurrent map writes goroutine 668 [running]: runtime.throw(0x27cb973, 0x15) /usr/local/go/src/runtime/panic.go:1116 +0x72 fp=0xc003a8c710 sp=0xc003a8c6e0 pc=0x437892 runtime.mapassign_faststr(0x23fc3a0, 0xc019650120, 0x27a837d, 0x6, 0xc00012f408) /usr/local/go/src/runtime/map_faststr.go:211 +0x3f1 fp=0xc003a8c778 sp=0xc003a8c710 pc=0x414811 github.com/databus23/helm-diff/v3/diff.setupDiffReport(...) /go/pkg/mod/github.com/databus23/helm-diff/[email protected]/diff/report.go:99 github.com/databus23/helm-diff/v3/diff.(*Report).setupReportFormat(0x3dafe80, 0x27a5ada, 0x4) /go/pkg/mod/github.com/databus23/helm-diff/[email protected]/diff/report.go:67 +0x111 fp=0xc003a8c7b0 sp=0xc003a8c778 pc=0x20e7291 github.com/databus23/helm-diff/v3/diff.Manifests(0xc009ffaf60, 0xc009ffb3e0, 0xc0061f73e0, 0x1, 0x1, 0xc0061f7300, 0x5, 0x27a5ada, 0x4, 0x2b26460, ...)
1 parent 8a3fb84 commit 9f6eb58

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

diff/diff.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
// Manifests diff on manifests
2222
func Manifests(oldIndex, newIndex map[string]*manifest.MappingResult, suppressedKinds []string, showSecrets bool, context int, output string, stripTrailingCR bool, to io.Writer) bool {
23+
report := Report{}
2324
report.setupReportFormat(output)
2425
seenAnyChanges := false
2526
emptyMapping := &manifest.MappingResult{}

diff/report.go

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -52,19 +52,17 @@ type ReportTemplateSpec struct {
5252
Change string
5353
}
5454

55-
var report Report
56-
5755
// setupReportFormat: process output argument.
5856
func (r *Report) setupReportFormat(format string) {
5957
switch format {
6058
case "simple":
61-
setupSimpleReport(&report)
59+
setupSimpleReport(r)
6260
case "template":
63-
setupTemplateReport(&report)
61+
setupTemplateReport(r)
6462
case "json":
65-
setupJSONReport(&report)
63+
setupJSONReport(r)
6664
default:
67-
setupDiffReport(&report)
65+
setupDiffReport(r)
6866
}
6967
}
7068

@@ -126,7 +124,7 @@ func printSimpleReport(r *Report, to io.Writer) {
126124
"MODIFY": 0,
127125
}
128126
for _, entry := range r.entries {
129-
fmt.Fprintf(to, ansi.Color("%s %s", report.format.changestyles[entry.changeType].color)+"\n",
127+
fmt.Fprintf(to, ansi.Color("%s %s", r.format.changestyles[entry.changeType].color)+"\n",
130128
entry.key,
131129
r.format.changestyles[entry.changeType].message,
132130
)

0 commit comments

Comments
 (0)