Skip to content

Commit ed21141

Browse files
committed
fix: channel race condition
1 parent 47091b6 commit ed21141

File tree

5 files changed

+28
-19
lines changed

5 files changed

+28
-19
lines changed

test/integration/components/testserver/testserver.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,51 +48,51 @@ func main() {
4848
}
4949
setupLog(&cfg)
5050

51-
wait := make(chan struct{})
51+
wait := make(chan struct{}, 1)
5252
go func() {
5353
std.Setup(cfg.STDPort)
54-
close(wait)
54+
wait <- struct{}{}
5555
}()
5656
go func() {
5757
std.SetupTLS(cfg.STDTLSPort)
58-
close(wait)
58+
wait <- struct{}{}
5959
}()
6060
go func() {
6161
gin2.SetMode(gin2.ReleaseMode)
6262
gin.Setup(cfg.GinPort)
63-
close(wait)
63+
wait <- struct{}{}
6464
}()
6565
go func() {
6666
gorilla.Setup(cfg.GorillaPort, cfg.STDPort)
67-
close(wait)
67+
wait <- struct{}{}
6868
}()
6969
go func() {
7070
gorillamid.Setup(cfg.GorillaMidPort, cfg.STDPort)
71-
close(wait)
71+
wait <- struct{}{}
7272
}()
7373
go func() {
7474
gorillamid2.Setup(cfg.GorillaMid2Port, cfg.STDPort)
75-
close(wait)
75+
wait <- struct{}{}
7676
}()
7777
go func() {
7878
err := grpctest.Setup(cfg.GRPCPort)
7979
if err != nil {
8080
slog.Error("HTTP server has unexpectedly stopped", "error", err)
8181
}
82-
close(wait)
82+
wait <- struct{}{}
8383
}()
8484

8585
go func() {
8686
err := grpctest.SetupTLS(cfg.GRPCTLSPort)
8787
if err != nil {
8888
slog.Error("HTTP server has unexpectedly stopped", "error", err)
8989
}
90-
close(wait)
90+
wait <- struct{}{}
9191
}()
9292

9393
go func() {
9494
jsonrpc.Setup(cfg.JSONRPCPort)
95-
close(wait)
95+
wait <- struct{}{}
9696
}()
9797

9898
// wait indefinitely unless any server crashes

test/integration/components/testserver_1.17/testserver.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -37,38 +37,38 @@ type config struct {
3737
func main() {
3838
cfg := config{}
3939
if err := env.Parse(&cfg); err != nil {
40-
fmt.Printf("can't load configuration from environment %w\n", err)
40+
fmt.Printf("can't load configuration from environment: %v\n", err)
4141
os.Exit(-1)
4242
}
4343

44-
wait := make(chan struct{})
44+
wait := make(chan struct{}, 1)
4545
go func() {
4646
std.Setup(cfg.STDPort)
47-
close(wait)
47+
wait <- struct{}{}
4848
}()
4949
go func() {
5050
gin2.SetMode(gin2.ReleaseMode)
5151
gin.Setup(cfg.GinPort)
52-
close(wait)
52+
wait <- struct{}{}
5353
}()
5454
go func() {
5555
gorilla.Setup(cfg.GorillaPort, cfg.STDPort)
56-
close(wait)
56+
wait <- struct{}{}
5757
}()
5858
go func() {
5959
gorillamid.Setup(cfg.GorillaMidPort, cfg.STDPort)
60-
close(wait)
60+
wait <- struct{}{}
6161
}()
6262
go func() {
6363
gorillamid2.Setup(cfg.GorillaMid2Port, cfg.STDPort)
64-
close(wait)
64+
wait <- struct{}{}
6565
}()
6666
go func() {
6767
err := grpctest.Setup()
6868
if err != nil {
69-
fmt.Printf("HTTP server has unexpectedly stopped %w\n", err)
69+
fmt.Printf("HTTP server has unexpectedly stopped: %v\n", err)
7070
}
71-
close(wait)
71+
wait <- struct{}{}
7272
}()
7373

7474
// wait indefinitely unless any server crashes

test/integration/docker-compose-multiexec-host.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ services:
2525
- "38080:8080"
2626
environment:
2727
LOG_LEVEL: DEBUG
28+
depends_on:
29+
testserver:
30+
condition: service_started
2831

2932
testserver1:
3033
build:

test/integration/docker-compose-multiexec-otelsdk.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ services:
1717
- "38080:8080"
1818
environment:
1919
LOG_LEVEL: DEBUG
20+
depends_on:
21+
testserver:
22+
condition: service_started
2023

2124
testserver1:
2225
build:

test/integration/docker-compose-multiexec.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ services:
2525
- "38080:8080"
2626
environment:
2727
LOG_LEVEL: DEBUG
28+
depends_on:
29+
testserver:
30+
condition: service_started
2831

2932
testserver1:
3033
build:

0 commit comments

Comments
 (0)