Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: return error if the startup process was killed by timeout #103

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

AleksandrKosovS
Copy link
Contributor

@AleksandrKosovS AleksandrKosovS commented Feb 12, 2025

Reason for This PR

This feature has a minor discrepancy: if the initialization process is terminated due to a timeout, the server incorrectly considers it a successful execution.

Description of Changes

This patch returns an error if ExitOnError is enabled.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

Change in the documentation

roadrunner-server/docs#47

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

Summary by CodeRabbit

  • Bug Fixes

    • Enhanced error reporting for the startup process, providing clear feedback when a timeout occurs based on user configuration settings.
  • New Features

    • Introduced a new configuration file for server settings, including parameters for initialization and error handling.
  • Tests

    • Added a new test case to verify error handling related to initialization timeouts for the TCP application.

Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

This pull request updates the error handling logic in the start method of the command struct by introducing a conditional return based on the ExitOnError flag. When the process is terminated due to a timeout, the method now returns an error if ExitOnError is set to true; otherwise, it returns nil. Additionally, a new configuration file has been added to simulate this scenario, and a corresponding test function has been introduced to verify that the timeout error is handled as expected.

Changes

File Path Change Summary
init.go Modified the start method in the command struct to conditionally return an error string when the process is killed by timeout and ExitOnError is true.
tests/configs/…/.rr-on-init-error-timeout.yaml Added a new configuration file specifying server settings, an on_init block with a 1-second sleep, a 1-nanosecond timeout, and exit on error directive.
tests/server_plugin_test.go Introduced TestAppTCPOnInitErrorTimeout, a new test function to assert the proper handling of initialization timeouts.

Sequence Diagram(s)

sequenceDiagram
    participant User as User/Application
    participant Cmd as Command.start()
    participant Config as ExitOnError Flag

    User->>Cmd: Invoke start()
    Cmd->>Config: Check ExitOnError setting
    alt ExitOnError is true
        Cmd-->>User: Return error "startup process killed by timeout"
    else
        Cmd-->>User: Return nil
    end
Loading

Possibly related PRs

Suggested reviewers

  • wolfy-j

Poem

I hop through code with ears up high,
Adjusting errors as time ticks by.
If timeouts knock and cause a fuss,
I signal errors without much muss.
A bunny coding with a joyful sigh—
Celebrating changes beneath the sky!
🐇💻


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between df441d9 and cc33c82.

⛔ Files ignored due to path filters (1)
  • go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • init.go (1 hunks)
  • tests/configs/.rr-on-init-error-timeout.yaml (1 hunks)
  • tests/server_plugin_test.go (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/configs/.rr-on-init-error-timeout.yaml
  • init.go
  • tests/server_plugin_test.go

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
tests/server_plugin_test.go (1)

271-294: Consider adding specific error message assertions.

While the test correctly verifies that an error occurs, it would be more robust to assert the specific error message expected when the startup process is killed by timeout.

 	_, err = cont.Serve()
 	require.Error(t, err)
+	require.Contains(t, err.Error(), "startup process has been killed by timeout")
tests/configs/.rr-on-init-error-timeout.yaml (1)

4-8: Add a comment explaining the test scenario.

Consider adding a YAML comment to explain that this configuration is designed to test timeout error handling by intentionally setting a very short timeout (1ns) for a longer operation (sleep 1s).

 server:
+  # Test configuration: Forces a timeout by setting 1ns timeout for a 1s sleep
   on_init:
     command: "sleep 1"
     exec_timeout: 1ns
     exit_on_error: true
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 884454d and 706eaaf.

⛔ Files ignored due to path filters (1)
  • go.work.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • init.go (1 hunks)
  • tests/configs/.rr-on-init-error-timeout.yaml (1 hunks)
  • tests/server_plugin_test.go (1 hunks)
🔇 Additional comments (1)
init.go (1)

66-70: LGTM! The error handling for timeout aligns with the PR objective.

The implementation correctly returns an error when ExitOnError is true and maintains backward compatibility by returning nil otherwise.

@AleksandrKosovS
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Feb 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@AleksandrKosovS
Copy link
Contributor Author

@coderabbitai review

Copy link

coderabbitai bot commented Feb 12, 2025

✅ Actions performed

Review triggered.

Note: CodeRabbit is an incremental review system and does not re-review already reviewed commits. This command is applicable only when automatic reviews are paused.

@rustatian rustatian added the enhancement New feature or request label Feb 12, 2025
@rustatian rustatian changed the title ExitOnError: return error if the startup process was killed by timeout chore: return error if the startup process was killed by timeout Feb 12, 2025
Copy link
Member

@rustatian rustatian left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @AleksandrKosovS 👍🏻

@rustatian rustatian merged commit 0917e26 into roadrunner-server:master Feb 12, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: ✅ Done
Development

Successfully merging this pull request may close these issues.

2 participants