linuxboot / linuxboot/contest

Race condition between TargetIn event in StepRunner and events emission in TestStep

Open
#84 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Go
Stars
20
Forks
17
PR merge metrics
No merged PRs in 30d

Description

The problem raises as we can't atomicly (at least without "ugly" locks in events emission) pass the target to the test step via channel and emit EventTargetIn event.

Currently we are having the following partial work-around:

https://github.com/linuxboot/contest/blob/main/pkg/runner/step_runner.go#L193

// put the target into step runner
`case sr.input <- tgt:`
// by the time we are hare, the test step could have already processed the target and emitted 100500 events
// test steps rarely emit events, so it is not a big issue. For consistency with TargetOut or TargetError I made this hack:
```
// we should always emit TargetIn before TargetOut or TargetError
// we have a race condition that outputLoop may receive result for this target first
// in that case we will emit TargetIn in outputLoop and should not emit it here
sr.mu.Lock()
if targetInfo.acquireTargetInEmission() {
if err := emitEvent(ctx, ev, target.EventTargetIn, tgt, nil); err != nil {
sr.setErrLocked(ctx, fmt.Errorf("failed to report target injection: %w", err))
}
}
sr.mu.Unlock()
```

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at pkg/runner/step_runner.go around line 193 and trace how StepRunner sends targets through its input channel, how TestStep emits events, and how outputLoop handles results. Reproduce or reason through the ordering race between EventTargetIn and TargetOut or TargetError, then define a synchronization approach that preserves the required event order and verify it with the existing test suite.

Written by the indexing model from the issue text.

Assessment

Tech stack
go
Domain
testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.