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: update streaming handler #196

Merged
merged 1 commit into from
Jan 10, 2024
Merged

chore: update streaming handler #196

merged 1 commit into from
Jan 10, 2024

Conversation

rustatian
Copy link
Member

@rustatian rustatian commented Jan 10, 2024

Reason for This PR

ref: roadrunner-server/roadrunner#1830

Description of Changes

  • properly finish the request and avoid blocking on the response channel.

License Acceptance

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

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

  • Refactor

    • Improved server shutdown process across different server types.
    • Enhanced error handling and worker pool management in HTTP handler.
  • Bug Fixes

    • Fixed an issue where the server would exit the loop prematurely on response errors.
  • Performance Improvements

    • Optimized worker pool signal handling for better resource management.
  • Documentation

    • Updated server timeout settings for clarity and performance tuning.

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian added the enhancement New feature or request label Jan 10, 2024
@rustatian rustatian requested a review from wolfy-j January 10, 2024 11:02
@rustatian rustatian self-assigned this Jan 10, 2024
Copy link

coderabbitai bot commented Jan 10, 2024

Walkthrough

The recent update introduces a new control flow for server and worker pool management. The server's shutdown process has been replaced with a close operation, and the worker pool can now be stopped using a select statement. Error handling has been refined to continue loop execution after a response error, and channel management within the worker pool has been streamlined.

Changes

Files Summary
handler/handler.go Introduced select for worker pool stop signal; refined error handling to continue after response errors; simplified getCh; replaced putCh with direct stopChPool insertion.
servers/fcgi/fcgi.go, servers/http11/http.go, servers/https/https.go Replaced server Shutdown methods with Close; adjusted timeout settings. Removed context package import in https.go.

Poem

🐰
In the burrows of the code, changes run deep,
Servers close gently, no longer to weep.
Workers halt softly with a select's embrace,
A rabbit's touch in the digital space.
🌟

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>.
    • Generate unit-tests for this file.
  • 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 tests 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 generate interesting stats about this repository from git and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit tests.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

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 as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Additionally, you can add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • 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/coderabbit-overrides.v2.json

CodeRabbit Discord Community

Join our Discord Community to get help, request features, and share feedback.

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.

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 2f83d76 and 194db51.
Files ignored due to filter (5)
  • go.mod
  • go.sum
  • go.work.sum
  • tests/go.mod
  • tests/go.sum
Files selected for processing (4)
  • handler/handler.go (2 hunks)
  • servers/fcgi/fcgi.go (2 hunks)
  • servers/http11/http.go (4 hunks)
  • servers/https/https.go (2 hunks)
Additional comments: 7
servers/fcgi/fcgi.go (1)
  • 61-61: The change from Shutdown to Close in the Stop method alters the server shutdown behavior. Ensure that this change is intentional and that the immediate termination of connections is the desired behavior, as Close does not wait for ongoing requests to finish.
servers/http11/http.go (2)
  • 49-52: The timeout settings for ReadTimeout, WriteTimeout, ReadHeaderTimeout, and IdleTimeout have been standardized to 5 minutes and 1 hour respectively. Confirm that these values are aligned with the expected load and performance characteristics of the server.

  • 105-105: The Stop method has been updated to use http.Close() instead of http.Shutdown(). This change should be carefully reviewed to ensure that it aligns with the desired server shutdown behavior, as Close will immediately terminate all connections.

servers/https/https.go (1)
  • 141-141: The Stop method has been updated to use https.Close() instead of https.Shutdown(context.Background()). As with the other server types, ensure that this change is intentional and that the immediate termination of connections is the desired behavior.
handler/handler.go (3)
  • 179-182: The addition of the select statement with a non-blocking send to stopCh is a good practice to prevent goroutine leaks. However, ensure that the downstream code is designed to handle this non-blocking behavior correctly.

  • 294-297: The getCh method has been simplified to directly retrieve a channel from the stopChPool. Ensure that the pool always contains properly initialized channels to prevent runtime panics.

  • 297-297: The putCh method now includes a non-blocking receive to ensure the channel is empty before putting it back into the pool. This is a good practice to avoid unexpected behavior due to leftover signals in the channel.

@rustatian rustatian merged commit 888e3da into master Jan 10, 2024
6 checks passed
@rustatian rustatian deleted the chore/streaming branch January 10, 2024 11:41
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.

1 participant