Skip to content

fix(spider-storage): Refill the inbound queue when the server restarts. - #398

Merged
sitaowang1998 merged 2 commits into
y-scope:mainfrom
LinZhihao-723:inbound-queue-fix
Jul 15, 2026
Merged

fix(spider-storage): Refill the inbound queue when the server restarts.#398
sitaowang1998 merged 2 commits into
y-scope:mainfrom
LinZhihao-723:inbound-queue-fix

Conversation

@LinZhihao-723

@LinZhihao-723 LinZhihao-723 commented Jul 15, 2026

Copy link
Copy Markdown
Member

Description

Before this PR, the inbound queue would never be refilled by the previously submitted running jobs when the storage server restarted. This PR fixes this problem by refilling the inbound queue when the server becomes serviceable (which avoids inbound queue deadlock as explained in the added comments).

Checklist

  • The PR satisfies the contribution guidelines.
  • This is a breaking change and that has been indicated in the PR title, OR this isn't a
    breaking change.
  • Necessary docs have been updated, OR no docs need to be updated.

Validation performed

  • Ensure all workflows pass.
  • Ensure that in a dev branch, the storage can recover from a failure while there are running jobs.

Summary by CodeRabbit

  • Bug Fixes
    • Improved error reporting when server configuration and runtime initialization fail.
    • Improved shutdown handling, including more reliable cancellation when stopping the service.
    • Ensured inbound task initialization failures are logged and trigger a controlled shutdown.
    • Enabled server startup and initialization tasks to proceed concurrently for smoother service readiness.

@coderabbitai

coderabbitai Bot commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The gRPC server entrypoint now logs configuration and runtime creation errors, starts the server concurrently, initializes ready tasks after spawning, and coordinates shutdown through cancellation tokens and runtime stop handling.

Changes

gRPC server lifecycle

Layer / File(s) Summary
Startup and cancellation flow
components/spider-storage/src/bin/grpc_server.rs
Configuration and Tokio runtime failures are logged before propagation. The gRPC server runs in a spawned task, ready tasks are resent after startup, initialization failures cancel the server, and shutdown errors are logged during server and runtime termination.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Possibly related PRs

  • y-scope/spider#324: Refactors spider-storage shutdown around cancellation tokens and background task termination.

Suggested reviewers: sitaowang1998

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately highlights the main change: refilling the inbound queue when the storage server restarts.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@LinZhihao-723
LinZhihao-723 marked this pull request as ready for review July 15, 2026 02:46
@LinZhihao-723
LinZhihao-723 requested review from a team and sitaowang1998 as code owners July 15, 2026 02:46

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@components/spider-storage/src/bin/grpc_server.rs`:
- Around line 97-109: Update the initialization and server execution flow around
service_state.resend_ready_tasks(), server.await, and runtime.stop() to retain
each result, always await runtime.stop() before returning, and then propagate
the first relevant failure, including queue initialization errors. Preserve the
existing error logging while ensuring cleanup runs unconditionally rather than
returning early via ?.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: 3b05e253-3620-4857-bc24-67f90ca7ee3c

📥 Commits

Reviewing files that changed from the base of the PR and between 86cf7a2 and 2effeab.

📒 Files selected for processing (1)
  • components/spider-storage/src/bin/grpc_server.rs

Comment on lines +97 to +109
if let Err(e) = service_state.resend_ready_tasks().await {
tracing::error!(error = % e, "Failed to initialize inbound queue.");
cancellation_token.cancel();
}

let stop_result = runtime.stop().await;
serve_result?;
stop_result?;
server
.await
.inspect_err(|e| tracing::error!(error = % e, "gRPC server panicked."))?
.inspect_err(|e| tracing::error!(error = % e, "gRPC server failure."))?;
runtime
.stop()
.await
.inspect_err(|e| tracing::error!(error = % e, "gRPC runtime failure."))?;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🩺 Stability & Availability | 🟠 Major | ⚡ Quick win

Always stop the runtime and propagate queue initialization failures.

The initialization error is discarded, allowing a clean server shutdown to return Ok(()). Conversely, either ? on Lines 102-105 returns before runtime.stop() executes. Capture all results, perform cleanup unconditionally, then propagate the errors.

Proposed sequencing
-    if let Err(e) = service_state.resend_ready_tasks().await {
-        tracing::error!(error = % e, "Failed to initialize inbound queue.");
+    let initialization_result = service_state.resend_ready_tasks().await.inspect_err(|e| {
+        tracing::error!(error = % e, "Failed to initialize inbound queue.");
+    });
+    if initialization_result.is_err() {
         cancellation_token.cancel();
     }

-    server
-        .await
-        .inspect_err(|e| tracing::error!(error = % e, "gRPC server panicked."))?
-        .inspect_err(|e| tracing::error!(error = % e, "gRPC server failure."))?;
-    runtime
-        .stop()
-        .await
-        .inspect_err(|e| tracing::error!(error = % e, "gRPC runtime failure."))?;
+    let server_result = server.await;
+    let stop_result = runtime.stop().await;
+
+    initialization_result?;
+    server_result
+        .inspect_err(|e| tracing::error!(error = % e, "gRPC server panicked."))?
+        .inspect_err(|e| tracing::error!(error = % e, "gRPC server failure."))?;
+    stop_result.inspect_err(|e| tracing::error!(error = % e, "gRPC runtime failure."))?;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
if let Err(e) = service_state.resend_ready_tasks().await {
tracing::error!(error = % e, "Failed to initialize inbound queue.");
cancellation_token.cancel();
}
let stop_result = runtime.stop().await;
serve_result?;
stop_result?;
server
.await
.inspect_err(|e| tracing::error!(error = % e, "gRPC server panicked."))?
.inspect_err(|e| tracing::error!(error = % e, "gRPC server failure."))?;
runtime
.stop()
.await
.inspect_err(|e| tracing::error!(error = % e, "gRPC runtime failure."))?;
let initialization_result = service_state.resend_ready_tasks().await.inspect_err(|e| {
tracing::error!(error = %e, "Failed to initialize inbound queue.");
});
if initialization_result.is_err() {
cancellation_token.cancel();
}
let server_result = server.await;
let stop_result = runtime.stop().await;
initialization_result?;
server_result
.inspect_err(|e| tracing::error!(error = %e, "gRPC server panicked."))?
.inspect_err(|e| tracing::error!(error = %e, "gRPC server failure."))?;
stop_result.inspect_err(|e| tracing::error!(error = %e, "gRPC runtime failure."))?;
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@components/spider-storage/src/bin/grpc_server.rs` around lines 97 - 109,
Update the initialization and server execution flow around
service_state.resend_ready_tasks(), server.await, and runtime.stop() to retain
each result, always await runtime.stop() before returning, and then propagate
the first relevant failure, including queue initialization errors. Preserve the
existing error logging while ensuring cleanup runs unconditionally rather than
returning early via ?.

@sitaowang1998
sitaowang1998 merged commit aaa824b into y-scope:main Jul 15, 2026
15 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants