Skip to content

Commit 1cb3ddd

Browse files
committed
Bound the completion check's re-upload rounds
A runtime ledger that keeps reporting a file as missing after a 2xx PUT sent the publish back to uploading forever: begin_finalizing resets the poll cap and every refresh extends the draft TTL. Give up after three rounds.
1 parent 9f19430 commit 1cb3ddd

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

‎includes/class-spacefast-static-publisher.php‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@ final class Spacefast_Static_Publisher {
1010
// so without the wait every retry would land within the same second.
1111
const MAX_TRANSIENT_RETRIES = 8;
1212
const MAX_RETRY_DELAY_SECONDS = 60;
13+
// Upload rounds the completion check may request before the publish gives
14+
// up on files the runtime keeps reporting as missing.
15+
const MAX_COMPLETION_ROUNDS = 3;
1316

1417
/**
1518
* Advance one bounded step of a Simply Static publish.
@@ -297,6 +300,11 @@ private static function poll_version( array $state, Spacefast_Client $client ):
297300
}
298301
$missing = $refresh['ok'] ? ( $refresh['data']['upload'] ?? null ) : null;
299302
if ( is_array( $missing ) && ! empty( $missing['targets'] ) ) {
303+
$rounds = (int) ( $state['completion_rounds'] ?? 0 ) + 1;
304+
if ( $rounds > self::MAX_COMPLETION_ROUNDS ) {
305+
throw new RuntimeException( 'Spacefast kept reporting uploaded files as missing.' );
306+
}
307+
$state['completion_rounds'] = $rounds;
300308
$state['phase'] = 'uploading';
301309
$state['upload'] = $missing;
302310
$state['next_target'] = 0;

‎tests/behavior.php‎

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1220,6 +1220,30 @@ static function () use ( &$missing_uploads ): array {
12201220
check( true === $missing_step['done'] && 2 === $missing_uploads, 'a file the server still lacks is uploaded again before waiting' );
12211221
check( 2 === $missing_resumes, 'the completion check runs again after the missing file lands' );
12221222

1223+
Spacefast_Static_Publisher::reset();
1224+
$stuck_client = new Spacefast_Client(
1225+
static function ( string $url, array $args ) use ( $retry_target ): array {
1226+
$upload = array(
1227+
'summary' => array( 'upload' => 1, 'reused' => 0, 'ignored' => 0 ),
1228+
'targets' => array( $retry_target ),
1229+
);
1230+
if ( str_contains( $url, '/uploads/resume' ) ) {
1231+
return response( 200, array( 'upload' => $upload ) );
1232+
}
1233+
return response( 201, array( 'versionId' => 'ver_stuck', 'upload' => $upload ) );
1234+
},
1235+
static fn (): array => response( 204 )
1236+
);
1237+
$stuck = false;
1238+
try {
1239+
for ( $i = 0; $i < 20; $i++ ) {
1240+
Spacefast_Static_Publisher::step( $archive, $stuck_client );
1241+
}
1242+
} catch ( RuntimeException $error ) {
1243+
$stuck = 'Spacefast kept reporting uploaded files as missing.' === $error->getMessage();
1244+
}
1245+
check( $stuck, 'a file the runtime never records ends the publish after bounded upload rounds' );
1246+
12231247
Spacefast_Static_Publisher::reset();
12241248
$rejecting_client = new Spacefast_Client(
12251249
static function ( string $url, array $args ) use ( $retry_target ): array {

0 commit comments

Comments
 (0)