Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
* develop:
  specify next release
  fix race condition on process executing too fast
  • Loading branch information
Baptouuuu committed Sep 18, 2024
2 parents f3eb571 + 35b3f1b commit 8457e71
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 5.2.3 - 2024-09-18

### Fixed

- A race condition where a process executing too fast was reported as failing even though it succeeded

## 5.2.2 - 2024-07-25

### Fixed
Expand Down
19 changes: 18 additions & 1 deletion src/Server/Process/Started.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ final class Started
private Maybe $content;
private Pid $pid;
private bool $executed = false;
/** @var int<0, 255> */
private ?int $exitCode = null;

/**
* @param callable(): array{0: resource, 1: array{0: resource, 1: resource, 2: resource}} $start
Expand Down Expand Up @@ -198,7 +200,22 @@ public function output(): Sequence
private function status(): array
{
/** @var Status */
return \proc_get_status($this->process);
$status = \proc_get_status($this->process);

// Here we cache the exit code as soon as we find the process stopped
// running. Otherwise if a process finishes before the first call to
// this method to retrieve the pid (done in this class constructor) then
// the following call when accessing the output will result in an exit
// code being `-1`.
if (!\is_null($this->exitCode)) {
$status['exitcode'] = $this->exitCode;
}

if ($status['running'] === false && \is_null($this->exitCode)) {
$this->exitCode = $status['exitcode'];
}

return $status;
}

/**
Expand Down
19 changes: 19 additions & 0 deletions tests/Server/Processes/UnixTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -252,4 +252,23 @@ public function testStopProcessEvenWhenPipesAreStillOpenAfterTheProcessBeingKill
// when done correctly then the foreach above would run forever
$this->assertTrue(true);
}

public function testRegressionWhenProcessFinishesTooFastItsFlaggedAsFailingEvenThoughItSucceeded()
{
$processes = Unix::of(
new Clock,
Streams::fromAmbientAuthority(),
new Usleep,
);

$this->assertTrue(
$processes
->execute(Command::foreground('df')->withShortOption('lh'))
->wait()
->match(
static fn() => true,
static fn() => false,
),
);
}
}

0 comments on commit 8457e71

Please sign in to comment.