Skip to content

Commit

Permalink
Merge pull request #680 from onflow/janez/fix-double-channel-closure
Browse files Browse the repository at this point in the history
Fix closing channel twice
  • Loading branch information
janezpodhostnik authored Nov 27, 2024
2 parents eb05840 + 70e7f9e commit c98427b
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions cmd/run/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"os"
"os/signal"
"strings"
"sync"
"syscall"
"time"

Expand Down Expand Up @@ -47,17 +48,21 @@ var Cmd = &cobra.Command{

done := make(chan struct{})
ready := make(chan struct{})
once := sync.Once{}
closeReady := func() {
once.Do(func() {
close(ready)
})
}
go func() {
defer close(done)
// In case an error happens before ready is called we need to close the ready channel
defer close(ready)
defer closeReady()

err := bootstrap.Run(
ctx,
cfg,
func() {
close(ready)
},
closeReady,
)
if err != nil && !errors.Is(err, context.Canceled) {
log.Err(err).Msg("Gateway runtime error")
Expand Down

0 comments on commit c98427b

Please sign in to comment.