Skip to content

Commit

Permalink
bug(executor): The init handler was not deterministic
Browse files Browse the repository at this point in the history
The order which reactor's init messages would arrive to the scheduler was not
deterministic, since it came from `for range topology {}` which is not guaranteed to be
the same in golang.
  • Loading branch information
symbiont-daniel-gustafsson committed Feb 2, 2021
1 parent b29f991 commit bddc98f
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions src/executor/executor.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"io/ioutil"
"net/http"
"sort"
"time"

"go.uber.org/zap"
Expand Down Expand Up @@ -144,9 +145,20 @@ func handleInits(topology Topology, m lib.Marshaler) http.HandlerFunc {
}

var inits []lib.Event
for component, reactor := range topology {

// we need make sure we output init messages in a deterministic order
// so we will output them in alphabetical order
reactors := make([]string, 0, len(topology))
{
for reactor, _ := range topology {
reactors = append(reactors, reactor)
}
sort.Strings(reactors)
}

for _, reactor := range reactors {
inits = append(inits,
lib.OutEventsToEvents(component, reactor.Init())...)
lib.OutEventsToEvents(reactor, topology[reactor].Init())...)
}

// Use `[]` for no events, rather than `null`, in the JSON encoding.
Expand Down

0 comments on commit bddc98f

Please sign in to comment.