Skip to content

Commit

Permalink
fix: race condition in setup (#1107)
Browse files Browse the repository at this point in the history
  • Loading branch information
hperl committed Nov 3, 2022
1 parent cf1eb9d commit 07dfce7
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions internal/driver/daemon.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,10 +120,16 @@ func (r *RegistryDefault) ServeAll(ctx context.Context) error {

eg := &errgroup.Group{}

eg.Go(r.serveRead(innerCtx, doneShutdown))
eg.Go(r.serveWrite(innerCtx, doneShutdown))
eg.Go(r.serveOPLSyntax(innerCtx, doneShutdown))
eg.Go(r.serveMetrics(innerCtx, doneShutdown))
// We need to separate the setup (invoking the functions that return the serve functions) from running the serve
// functions to mitigate race contitions in the HTTP router.
for _, serve := range []func() error{
r.serveRead(innerCtx, doneShutdown),
r.serveWrite(innerCtx, doneShutdown),
r.serveOPLSyntax(innerCtx, doneShutdown),
r.serveMetrics(innerCtx, doneShutdown),
} {
eg.Go(serve)
}

return eg.Wait()
}
Expand Down

0 comments on commit 07dfce7

Please sign in to comment.