Skip to content

Go: refactor ragflow_server.go - #17494

Merged
JinHai-CN merged 11 commits into
infiniflow:mainfrom
JinHai-CN:fix592
Jul 29, 2026
Merged

JinHai-CN merged 11 commits into
infiniflow:mainfrom
JinHai-CN:fix592

Conversation

@JinHai-CN

Copy link
Copy Markdown
Member

No description provided.

@JinHai-CN
JinHai-CN marked this pull request as ready for review July 28, 2026 13:06
@dosubot dosubot Bot added the size:L This PR changes 100-499 lines, ignoring generated files. label Jul 28, 2026
@coderabbitai

coderabbitai Bot commented Jul 28, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The 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.

Changes

Server lifecycle coordination

Layer / File(s) Summary
Heartbeat configuration contract
internal/server/config.go, conf/service_conf.yaml, docker/service_conf.yaml.template
Adds GeneralConfig.HeartbeatInterval and defines the default heartbeat interval in both YAML configurations.
Mode context and runner lifecycle
cmd/ragflow_server.go, internal/admin/license_ee.go, internal/admin/service_ee.go
Routes API, admin, ingestor, and syncer modes through shared context and configuration, updates shutdown and heartbeat handling, extends syncer help, and invokes license initialization for admin mode.
API server shutdown integration
cmd/ragflow_server.go
Passes context and configuration into startServer, uses the configured heartbeat interval, updates Dify retrieval wiring and comment text, and performs timed graceful shutdown after context cancellation.

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
Loading

Suggested reviewers: xugangqiang

Poem

A bunny hops through signals bright,
With heartbeats timed just right.
The syncer joins the help parade,
And gentle shutdowns are neatly made.
License seeds the admin day—
Then all the runners rest away.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning No PR description was added, so the required Summary section and context are missing. Add a Summary section that briefly explains the goal, background, and intended impact of the refactor.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title is concise and accurately describes the main change: a refactor of ragflow_server.go.
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.

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.

@JinHai-CN JinHai-CN added the ci Continue Integration label Jul 28, 2026

@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: 2

🧹 Nitpick comments (1)
internal/server/config.go (1)

61-64: 🎯 Functional Correctness | 🔵 Trivial | ⚡ Quick win

Use one duration representation end-to-end.

HeartbeatInterval is decoded as a time.Duration, but the heartbeat reporters pass it to NewScheduledTask as config.General.HeartbeatInterval*time.Second: a duration-form value such as 30s would 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

📥 Commits

Reviewing files that changed from the base of the PR and between e91da6b and 8d8846a.

📒 Files selected for processing (5)
  • cmd/ragflow_server.go
  • conf/service_conf.yaml
  • docker/service_conf.yaml.template
  • internal/admin/license_ee.go
  • internal/server/config.go

Comment thread cmd/ragflow_server.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)

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

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.

Suggested change
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.

Comment thread cmd/ragflow_server.go Resolved
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>
Signed-off-by: Jin Hai <[email protected]>

@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 `@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

📥 Commits

Reviewing files that changed from the base of the PR and between 8d8846a and 3c9fbbb.

📒 Files selected for processing (2)
  • cmd/ragflow_server.go
  • internal/admin/service_ee.go

Comment thread cmd/ragflow_server.go

fmt.Printf("Failed to start %s server: %v\n", *arguments.mode, err)
os.Exit(1)
return

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.

🎯 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-L270
  • cmd/ragflow_server.go#L307-L307
  • cmd/ragflow_server.go#L380-L380
  • cmd/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.

@JinHai-CN
JinHai-CN merged commit 0eb8e0b into infiniflow:main Jul 29, 2026
9 of 10 checks passed
@coderabbitai coderabbitai Bot mentioned this pull request Aug 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ci Continue Integration size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant