fix(spider-storage): Refill the inbound queue when the server restarts. - #398
Conversation
WalkthroughThe 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. ChangesgRPC server lifecycle
Estimated code review effort: 3 (Moderate) | ~20 minutes Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (1)
components/spider-storage/src/bin/grpc_server.rs
| 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."))?; |
There was a problem hiding this comment.
🩺 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.
| 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 ?.
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
breaking change.
Validation performed
Summary by CodeRabbit