Skip to content

Commit

Permalink
Fix Nomad evaluation race condition
Browse files Browse the repository at this point in the history
that was caused by Nomad sending similar evaluation information multiple times and Poseidon closing the response channel only asynchronously.
  • Loading branch information
mpass99 authored and MrSerth committed Aug 1, 2024
1 parent 5ddfb91 commit 0cffdd5
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion internal/nomad/nomad.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,6 @@ func (a *APIClient) LoadRunnerJobs(environmentID dto.EnvironmentID) ([]*nomadApi
func (a *APIClient) MonitorEvaluation(evaluationID string, ctx context.Context) (err error) {
evaluationErrorChannel := make(chan error, 1)
a.evaluations.Add(evaluationID, evaluationErrorChannel)
defer a.evaluations.Delete(evaluationID)

if !a.isListening {
var cancel context.CancelFunc
Expand Down Expand Up @@ -327,6 +326,7 @@ func handleEvaluationEvent(evaluations storage.Storage[chan error], event *nomad
select {
case resultChannel <- evalErr:
close(resultChannel)
evaluations.Delete(eval.ID)
case <-time.After(resultChannelWriteTimeout):
log.WithField("length", len(resultChannel)).
WithField("eval", eval).
Expand Down

0 comments on commit 0cffdd5

Please sign in to comment.