Repository navigation
Go: refactor ragflow_server.go - #17494
Conversation
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
📝 WalkthroughWalkthroughThe server now shares a signal-derived context and loaded configuration across mode runners, uses configurable heartbeat intervals, and performs context-driven graceful shutdown. Help output includes syncer usage, and admin startup invokes license initialization. ChangesServer lifecycle coordination
Estimated code review effort: 3 (Moderate) | ~20 minutes Sequence Diagram(s)sequenceDiagram
participant OS
participant main
participant ModeRunner
participant startServer
OS->>main: SIGINT, SIGTERM, or SIGQUIT
main->>ModeRunner: pass shared ctx and config
ModeRunner->>startServer: start API with ctx and config
main->>startServer: cancel ctx
startServer->>startServer: wait for ctx.Done()
startServer->>startServer: graceful shutdown with timeout
Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
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: 2
🧹 Nitpick comments (1)
internal/server/config.go (1)
61-64: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick winUse one duration representation end-to-end.
HeartbeatIntervalis decoded as atime.Duration, but the heartbeat reporters pass it toNewScheduledTaskasconfig.General.HeartbeatInterval*time.Second: a duration-form value such as30swould be scheduled at a 30-second-multiplied interval. Use an explicit integer-seconds field, or decode and pass duration values without multiplying. It should also reject non-positive intervals.🤖 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 `@internal/server/config.go` around lines 61 - 64, Make the HeartbeatInterval representation consistent from GeneralConfig through the heartbeat reporters and NewScheduledTask: either store integer seconds and multiply exactly once, or preserve time.Duration values and pass them without multiplying. Update the relevant validation to reject zero or negative intervals before scheduling, using the existing HeartbeatInterval and heartbeat scheduling symbols.
🤖 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 `@cmd/ragflow_server.go`:
- Around line 612-620: Update the comments for both heartbeat schedulers in
cmd/ragflow_server.go at lines 612-620 and 897-905 to state that they run at the
configured config.General.HeartbeatInterval rather than a fixed 30-second
interval; make no code changes to the heartbeatReporter scheduling logic.
- Line 217: Update the signal.NotifyContext call in the server startup flow to
include syscall.SIGUSR2 alongside the existing shutdown signals, preserving the
graceful cancellation path for HTTP server, workers, and heartbeat cleanup.
---
Nitpick comments:
In `@internal/server/config.go`:
- Around line 61-64: Make the HeartbeatInterval representation consistent from
GeneralConfig through the heartbeat reporters and NewScheduledTask: either store
integer seconds and multiply exactly once, or preserve time.Duration values and
pass them without multiplying. Update the relevant validation to reject zero or
negative intervals before scheduling, using the existing HeartbeatInterval and
heartbeat scheduling symbols.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 4a46b266-80f5-445b-b67d-21254db1d5d6
📒 Files selected for processing (5)
cmd/ragflow_server.goconf/service_conf.yamldocker/service_conf.yaml.templateinternal/admin/license_ee.gointernal/server/config.go
|
|
||
| func main() { | ||
| ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGUSR2) | ||
| ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) |
There was a problem hiding this comment.
🩺 Stability & Availability | 🟠 Major | ⚡ Quick win
Preserve the existing SIGUSR2 graceful-shutdown path.
Dropping SIGUSR2 means deployments using it no longer cancel ctx; its default action can terminate the process before the HTTP server, workers, and heartbeat reporter stop cleanly. Keep it registered unless all callers have migrated to another signal.
Proposed fix
- ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
+ ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGUSR2)📝 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.
| ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) | |
| ctx, cancel := signal.NotifyContext(context.Background(), syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGUSR2) |
🤖 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 `@cmd/ragflow_server.go` at line 217, Update the signal.NotifyContext call in
the server startup flow to include syscall.SIGUSR2 alongside the existing
shutdown signals, preserving the graceful cancellation path for HTTP server,
workers, and heartbeat cleanup.
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
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 `@cmd/ragflow_server.go`:
- Line 240: Refactor startup into a run() error helper so its deferred cleanup
executes, and have main call os.Exit(1) when run() returns an error. In
cmd/ragflow_server.go at lines 240, 270, 307, 380, and 390-412, replace normal
returns with error propagation for local-variable initialization, configuration
initialization, invalid mode, EE startup, mode-runner failures, and invalid
dispatches.
🪄 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: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 17ad92fa-671b-4778-b836-a748af0c61a5
📒 Files selected for processing (2)
cmd/ragflow_server.gointernal/admin/service_ee.go
|
|
||
| fmt.Printf("Failed to start %s server: %v\n", *arguments.mode, err) | ||
| os.Exit(1) | ||
| return |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟠 Major | ⚡ Quick win
Return a non-zero status for startup failures.
These branches now return normally from main, so failed startup exits with status 0. Supervisors and deployment scripts will treat a failed server launch as successful. Move startup into a run() error helper so its defers execute, then have main call os.Exit(1) when run() returns an error.
cmd/ragflow_server.go#L240-L240: propagate the local-variable initialization error.cmd/ragflow_server.go#L270-L270: propagate the configuration initialization error.cmd/ragflow_server.go#L307-L307: propagate the invalid-mode error.cmd/ragflow_server.go#L380-L380: propagate the EE server startup error.cmd/ragflow_server.go#L390-L412: propagate mode-runner failures and invalid dispatches.
📍 Affects 1 file
cmd/ragflow_server.go#L240-L240(this comment)cmd/ragflow_server.go#L270-L270cmd/ragflow_server.go#L307-L307cmd/ragflow_server.go#L380-L380cmd/ragflow_server.go#L390-L412
🤖 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 `@cmd/ragflow_server.go` at line 240, Refactor startup into a run() error
helper so its deferred cleanup executes, and have main call os.Exit(1) when
run() returns an error. In cmd/ragflow_server.go at lines 240, 270, 307, 380,
and 390-412, replace normal returns with error propagation for local-variable
initialization, configuration initialization, invalid mode, EE startup,
mode-runner failures, and invalid dispatches.
No description provided.