Skip to content

Commit d09ff45

Browse files
smirautkuozdemir
andcommitted
fix: race in wait value
See #46 The issue was that `.TryGet()` can return `ok == true` and `value == nil` which would crash the whole process. From `relay.go`, `runToPeer` function: ```go stream, ok := wv.TryGet() if !ok { // some handling } // here we assume that `stream != nil`, but due to the bug // in waitValue, it's not true stream.Send(...) // <<<< panic ``` Signed-off-by: Andrey Smirnov <[email protected]> Co-authored-by: Utku Ozdemir <[email protected]>
1 parent d2a79e0 commit d09ff45

File tree

6 files changed

+199
-115
lines changed

6 files changed

+199
-115
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2025-01-22T18:43:52Z by kres 3075de9.
3+
# Generated on 2025-06-05T10:30:41Z by kres fc6afbe.
44

55
name: default
66
concurrency:
@@ -32,7 +32,7 @@ jobs:
3232
steps:
3333
- name: gather-system-info
3434
id: system-info
35-
uses: kenchan0130/[email protected].0
35+
uses: kenchan0130/[email protected].1
3636
continue-on-error: true
3737
- name: print-system-info
3838
run: |

.golangci.yml

Lines changed: 107 additions & 101 deletions
Original file line numberDiff line numberDiff line change
@@ -1,116 +1,32 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2025-03-07T16:55:05Z by kres ef4356e.
3+
# Generated on 2025-06-05T10:30:41Z by kres fc6afbe.
4+
5+
version: "2"
46

57
# options for analysis running
68
run:
7-
timeout: 10m
9+
modules-download-mode: readonly
810
issues-exit-code: 1
911
tests: true
10-
build-tags: [ ]
11-
modules-download-mode: readonly
1212

1313
# output configuration options
1414
output:
1515
formats:
16-
- format: colored-line-number
16+
text:
1717
path: stdout
18-
print-issued-lines: true
19-
print-linter-name: true
18+
print-issued-lines: true
19+
print-linter-name: true
2020
path-prefix: ""
2121

22-
# all available settings of specific linters
23-
linters-settings:
24-
dogsled:
25-
max-blank-identifiers: 2
26-
dupl:
27-
threshold: 150
28-
errcheck:
29-
check-type-assertions: true
30-
check-blank: true
31-
exhaustive:
32-
default-signifies-exhaustive: false
33-
gci:
34-
sections:
35-
- standard # Standard section: captures all standard packages.
36-
- default # Default section: contains all imports that could not be matched to another section type.
37-
- localmodule # Imports from the same module.
38-
gocognit:
39-
min-complexity: 30
40-
nestif:
41-
min-complexity: 5
42-
goconst:
43-
min-len: 3
44-
min-occurrences: 3
45-
gocritic:
46-
disabled-checks: [ ]
47-
gocyclo:
48-
min-complexity: 20
49-
godot:
50-
scope: declarations
51-
gofmt:
52-
simplify: true
53-
gomodguard: { }
54-
govet:
55-
enable-all: true
56-
lll:
57-
line-length: 200
58-
tab-width: 4
59-
misspell:
60-
locale: US
61-
ignore-words: [ ]
62-
nakedret:
63-
max-func-lines: 30
64-
prealloc:
65-
simple: true
66-
range-loops: true # Report preallocation suggestions on range loops, true by default
67-
for-loops: false # Report preallocation suggestions on for loops, false by default
68-
nolintlint:
69-
allow-unused: false
70-
allow-no-explanation: [ ]
71-
require-explanation: false
72-
require-specific: true
73-
rowserrcheck: { }
74-
testpackage: { }
75-
unparam:
76-
check-exported: false
77-
unused:
78-
local-variables-are-used: false
79-
whitespace:
80-
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
81-
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
82-
wsl:
83-
strict-append: true
84-
allow-assign-and-call: true
85-
allow-multiline-assign: true
86-
allow-cuddle-declarations: false
87-
allow-trailing-comment: false
88-
force-case-trailing-whitespace: 0
89-
force-err-cuddling: false
90-
allow-separated-leading-comment: false
91-
gofumpt:
92-
extra-rules: false
93-
cyclop:
94-
# the maximal code complexity to report
95-
max-complexity: 20
96-
depguard:
97-
rules:
98-
prevent_unmaintained_packages:
99-
list-mode: lax # allow unless explicitly denied
100-
files:
101-
- $all
102-
deny:
103-
- pkg: io/ioutil
104-
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
10522

10623
linters:
107-
enable-all: true
108-
disable-all: false
109-
fast: false
24+
default: all
11025
disable:
11126
- exhaustruct
11227
- err113
11328
- forbidigo
29+
- funcorder
11430
- funlen
11531
- gochecknoglobals
11632
- gochecknoinits
@@ -131,19 +47,109 @@ linters:
13147
- testifylint # complains about our assert recorder and has a number of false positives for assert.Greater(t, thing, 1)
13248
- protogetter # complains about us using Value field on typed spec, instead of GetValue which has a different signature
13349
- perfsprint # complains about us using fmt.Sprintf in non-performance critical code, updating just kres took too long
134-
- goimports # same as gci
13550
- musttag # seems to be broken - goes into imported libraries and reports issues there
51+
- nolintlint # gives false positives - disable until https://github.com/golangci/golangci-lint/issues/3228 is resolved
52+
# all available settings of specific linters
53+
settings:
54+
cyclop:
55+
# the maximal code complexity to report
56+
max-complexity: 20
57+
dogsled:
58+
max-blank-identifiers: 2
59+
dupl:
60+
threshold: 150
61+
errcheck:
62+
check-type-assertions: true
63+
check-blank: true
64+
exhaustive:
65+
default-signifies-exhaustive: false
66+
gocognit:
67+
min-complexity: 30
68+
nestif:
69+
min-complexity: 5
70+
goconst:
71+
min-len: 3
72+
min-occurrences: 3
73+
gocritic:
74+
disabled-checks: [ ]
75+
gocyclo:
76+
min-complexity: 20
77+
godot:
78+
scope: declarations
79+
gomodguard: { }
80+
govet:
81+
enable-all: true
82+
lll:
83+
line-length: 200
84+
tab-width: 4
85+
misspell:
86+
locale: US
87+
nakedret:
88+
max-func-lines: 30
89+
prealloc:
90+
simple: true
91+
range-loops: true # Report preallocation suggestions on range loops, true by default
92+
for-loops: false # Report preallocation suggestions on for loops, false by default
93+
rowserrcheck: { }
94+
testpackage: { }
95+
unparam:
96+
check-exported: false
97+
unused:
98+
local-variables-are-used: false
99+
whitespace:
100+
multi-if: false # Enforces newlines (or comments) after every multi-line if statement
101+
multi-func: false # Enforces newlines (or comments) after every multi-line function signature
102+
wsl:
103+
strict-append: true
104+
allow-assign-and-call: true
105+
allow-multiline-assign: true
106+
allow-trailing-comment: false
107+
force-case-trailing-whitespace: 0
108+
allow-separated-leading-comment: false
109+
allow-cuddle-declarations: false
110+
force-err-cuddling: false
111+
depguard:
112+
rules:
113+
prevent_unmaintained_packages:
114+
list-mode: lax # allow unless explicitly denied
115+
files:
116+
- $all
117+
deny:
118+
- pkg: io/ioutil
119+
desc: "replaced by io and os packages since Go 1.16: https://tip.golang.org/doc/go1.16#ioutil"
136120

121+
exclusions:
122+
generated: lax
123+
paths:
124+
- third_party$
125+
- builtin$
126+
- examples$
137127
issues:
138-
exclude: [ ]
139-
exclude-rules: [ ]
140-
exclude-use-default: false
141-
exclude-case-sensitive: false
142128
max-issues-per-linter: 10
143129
max-same-issues: 3
144-
new: false
145130
uniq-by-line: true
131+
new: false
146132

147133
severity:
148-
default-severity: error
149-
case-sensitive: false
134+
default: error
135+
formatters:
136+
enable:
137+
- gci
138+
- gofmt
139+
- gofumpt
140+
settings:
141+
gci:
142+
sections:
143+
- standard
144+
- default
145+
- localmodule
146+
gofmt:
147+
simplify: true
148+
gofumpt:
149+
extra-rules: false
150+
exclusions:
151+
generated: lax
152+
paths:
153+
- third_party$
154+
- builtin$
155+
- examples$

Dockerfile

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
1-
# syntax = docker/dockerfile-upstream:1.14.0-labs
1+
# syntax = docker/dockerfile-upstream:1.16.0-labs
22

33
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
44
#
5-
# Generated on 2025-03-07T16:55:05Z by kres ef4356e.
5+
# Generated on 2025-06-05T10:30:41Z by kres fc6afbe.
66

77
ARG TOOLCHAIN
88

99
# runs markdownlint
10-
FROM docker.io/oven/bun:1.2.4-alpine AS lint-markdown
10+
FROM docker.io/oven/bun:1.2.15-alpine AS lint-markdown
1111
WORKDIR /src
12-
RUN bun i markdownlint-cli@0.44.0 [email protected]
12+
RUN bun i markdownlint-cli@0.45.0 [email protected]
1313
COPY .markdownlint.json .
1414
COPY ./README.md ./README.md
1515
RUN bunx markdownlint --ignore "CHANGELOG.md" --ignore "**/node_modules/**" --ignore '**/hack/chglog/**' --rules sentences-per-line .
@@ -37,6 +37,9 @@ ENV GOPATH=/go
3737
ARG GOIMPORTS_VERSION
3838
RUN --mount=type=cache,target=/root/.cache/go-build,id=siderolink/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=siderolink/go/pkg go install golang.org/x/tools/cmd/goimports@v${GOIMPORTS_VERSION}
3939
RUN mv /go/bin/goimports /bin
40+
ARG GOMOCK_VERSION
41+
RUN --mount=type=cache,target=/root/.cache/go-build,id=siderolink/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=siderolink/go/pkg go install go.uber.org/mock/mockgen@v${GOMOCK_VERSION}
42+
RUN mv /go/bin/mockgen /bin
4043
ARG PROTOBUF_GO_VERSION
4144
RUN --mount=type=cache,target=/root/.cache/go-build,id=siderolink/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=siderolink/go/pkg go install google.golang.org/protobuf/cmd/protoc-gen-go@v${PROTOBUF_GO_VERSION}
4245
RUN mv /go/bin/protoc-gen-go /bin
@@ -53,7 +56,7 @@ ARG DEEPCOPY_VERSION
5356
RUN --mount=type=cache,target=/root/.cache/go-build,id=siderolink/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=siderolink/go/pkg go install github.com/siderolabs/deep-copy@${DEEPCOPY_VERSION} \
5457
&& mv /go/bin/deep-copy /bin/deep-copy
5558
ARG GOLANGCILINT_VERSION
56-
RUN --mount=type=cache,target=/root/.cache/go-build,id=siderolink/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=siderolink/go/pkg go install github.com/golangci/golangci-lint/cmd/golangci-lint@${GOLANGCILINT_VERSION} \
59+
RUN --mount=type=cache,target=/root/.cache/go-build,id=siderolink/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=siderolink/go/pkg go install github.com/golangci/golangci-lint/v2/cmd/golangci-lint@${GOLANGCILINT_VERSION} \
5760
&& mv /go/bin/golangci-lint /bin/golangci-lint
5861
RUN --mount=type=cache,target=/root/.cache/go-build,id=siderolink/root/.cache/go-build --mount=type=cache,target=/go/pkg,id=siderolink/go/pkg go install golang.org/x/vuln/cmd/govulncheck@latest \
5962
&& mv /go/bin/govulncheck /bin/govulncheck
@@ -94,7 +97,6 @@ FROM base AS lint-golangci-lint
9497
WORKDIR /src
9598
COPY .golangci.yml .
9699
ENV GOGC=50
97-
RUN golangci-lint config verify --config .golangci.yml
98100
RUN --mount=type=cache,target=/root/.cache/go-build,id=siderolink/root/.cache/go-build --mount=type=cache,target=/root/.cache/golangci-lint,id=siderolink/root/.cache/golangci-lint,sharing=locked --mount=type=cache,target=/go/pkg,id=siderolink/go/pkg golangci-lint run --config .golangci.yml
99101

100102
# runs govulncheck

Makefile

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# THIS FILE WAS AUTOMATICALLY GENERATED, PLEASE DO NOT EDIT.
22
#
3-
# Generated on 2025-03-07T16:55:05Z by kres ef4356e.
3+
# Generated on 2025-06-05T10:30:41Z by kres fc6afbe.
44

55
# common variables
66

@@ -17,19 +17,21 @@ WITH_RACE ?= false
1717
REGISTRY ?= ghcr.io
1818
USERNAME ?= siderolabs
1919
REGISTRY_AND_USERNAME ?= $(REGISTRY)/$(USERNAME)
20-
PROTOBUF_GO_VERSION ?= 1.36.5
20+
PROTOBUF_GO_VERSION ?= 1.36.6
2121
GRPC_GO_VERSION ?= 1.5.1
2222
GRPC_GATEWAY_VERSION ?= 2.26.3
2323
VTPROTOBUF_VERSION ?= 0.6.0
24-
GOIMPORTS_VERSION ?= 0.30.0
24+
GOIMPORTS_VERSION ?= 0.33.0
25+
GOMOCK_VERSION ?= 0.5.2
2526
DEEPCOPY_VERSION ?= v0.5.6
26-
GOLANGCILINT_VERSION ?= v1.64.6
27-
GOFUMPT_VERSION ?= v0.7.0
28-
GO_VERSION ?= 1.24.1
27+
GOLANGCILINT_VERSION ?= v2.1.6
28+
GOFUMPT_VERSION ?= v0.8.0
29+
GO_VERSION ?= 1.24.3
2930
GO_BUILDFLAGS ?=
3031
GO_LDFLAGS ?=
3132
CGO_ENABLED ?= 0
3233
GOTOOLCHAIN ?= local
34+
GOEXPERIMENT ?= synctest
3335
TESTPKGS ?= ./...
3436
KRES_IMAGE ?= ghcr.io/siderolabs/kres:latest
3537
CONFORMANCE_IMAGE ?= ghcr.io/siderolabs/conform:latest
@@ -65,6 +67,7 @@ COMMON_ARGS += --build-arg=GRPC_GO_VERSION="$(GRPC_GO_VERSION)"
6567
COMMON_ARGS += --build-arg=GRPC_GATEWAY_VERSION="$(GRPC_GATEWAY_VERSION)"
6668
COMMON_ARGS += --build-arg=VTPROTOBUF_VERSION="$(VTPROTOBUF_VERSION)"
6769
COMMON_ARGS += --build-arg=GOIMPORTS_VERSION="$(GOIMPORTS_VERSION)"
70+
COMMON_ARGS += --build-arg=GOMOCK_VERSION="$(GOMOCK_VERSION)"
6871
COMMON_ARGS += --build-arg=DEEPCOPY_VERSION="$(DEEPCOPY_VERSION)"
6972
COMMON_ARGS += --build-arg=GOLANGCILINT_VERSION="$(GOLANGCILINT_VERSION)"
7073
COMMON_ARGS += --build-arg=GOFUMPT_VERSION="$(GOFUMPT_VERSION)"

internal/wait/value.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,13 @@ func (wv *Value[T]) TryGet() (T, bool) {
7575
select {
7676
case <-set:
7777
wv.mx.Lock()
78+
79+
if wv.set == nil {
80+
wv.mx.Unlock()
81+
82+
return *new(T), false
83+
}
84+
7885
value := wv.value
7986
wv.mx.Unlock()
8087

0 commit comments

Comments
 (0)