Skip to content

fix: use bytes as values in proto to support non-utf8 payloads#209

Merged
rustatian merged 6 commits intomasterfrom
fix/use-bytes-for-proto
Jan 13, 2025
Merged

fix: use bytes as values in proto to support non-utf8 payloads#209
rustatian merged 6 commits intomasterfrom
fix/use-bytes-for-proto

Conversation

@rustatian
Copy link
Member

@rustatian rustatian commented Jan 13, 2025

Reason for This PR

closes: roadrunner-server/roadrunner#2104

Description of Changes

  • Use []bytes instead of utf-8 strings to pass any data to the PHP worker (even non utf-8).

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

  • Chores

    • Updated GitHub Actions workflow to use newer versions of linters and PHP
    • Upgraded dependency github.com/roadrunner-server/api/v4 to v4.18.1
  • Bug Fixes

    • Corrected error handling in test cases
    • Improved type conversions in HTTP response handling
  • Tests

    • Minor updates to test configuration and error checking

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
@rustatian rustatian added the bug Something isn't working label Jan 13, 2025
@rustatian rustatian self-assigned this Jan 13, 2025
@coderabbitai
Copy link

coderabbitai bot commented Jan 13, 2025

Walkthrough

This pull request introduces several updates across the project's configuration and code files. The changes include upgrading the GolangCI linter version, updating PHP and Go dependency versions, and modifying type conversion and error handling in HTTP-related code. The modifications focus on improving type safety, error handling, and dependency management in the project's GitHub Actions workflows and Go code.

Changes

File Change Summary
.github/workflows/linters.yml Updated GolangCI linter version from v1.61 to v1.62
.github/workflows/linux.yml Updated PHP version in testing matrix from 8.3 to 8.4
go.mod Updated github.com/roadrunner-server/api/v4 dependency from v4.17.0 to v4.18.1
tests/go.mod Updated github.com/roadrunner-server/api/v4 dependency from v4.17.0 to v4.18.1
handler/convert.go Modified header and cookie value conversion to explicitly use byte slice conversion
handler/response.go Updated type conversions for HTTP2 push headers and response headers, simplified flushing mechanism
tests/handler_test.go Corrected error handling comparison in errors.Is() function

Assessment against linked issues

Objective Addressed Explanation
Handle invalid UTF-8 in HTTP requests [#2104] Changes do not directly address UTF-8 handling in request parsing

Poem

🐰 Hop, hop, through code's domain,
Linters upgraded, dependencies gain!
Byte slices dance, errors take flight,
Our workflow shines, oh so bright! 🚀
CodeRabbit's magic, version by version we climb! 🌈

Finishing Touches

  • 📝 Generate Docstrings (Beta)

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.

Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
Signed-off-by: Valery Piashchynski <piashchynski.valery@gmail.com>
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: 1

🧹 Nitpick comments (1)
handler/convert.go (1)

20-23: LGTM! Proper handling of non-UTF-8 header values.

The conversion of header values to byte slices ensures proper handling of non-UTF-8 encoded data, which aligns well with the PR objective.

Consider pre-allocating the Value slice to reduce allocations:

 if resp[k] == nil {
-  resp[k] = &httpV1proto.HeaderValue{}
+  resp[k] = &httpV1proto.HeaderValue{
+    Value: make([][]byte, 0, len(v))
+  }
 }
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 5b3219c and e2479e6.

⛔ Files ignored due to path filters (3)
  • go.sum is excluded by !**/*.sum
  • go.work.sum is excluded by !**/*.sum
  • tests/go.sum is excluded by !**/*.sum
📒 Files selected for processing (7)
  • .github/workflows/linters.yml (1 hunks)
  • .github/workflows/linux.yml (1 hunks)
  • go.mod (1 hunks)
  • handler/convert.go (2 hunks)
  • handler/response.go (3 hunks)
  • tests/go.mod (1 hunks)
  • tests/handler_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • go.mod
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: HTTP plugin (Go stable, PHP 8.4, OS ubuntu-latest)
🔇 Additional comments (8)
handler/convert.go (1)

41-41: LGTM! Consistent byte-based handling for cookie values.

Converting cookie values to byte slices maintains consistency with header handling and supports non-UTF-8 data.

handler/response.go (3)

57-57: LGTM! Safe conversion for HTTP/2 push paths.

Converting byte slices to strings for HTTP/2 push paths is necessary as http.Pusher requires string paths. The conversion is safe here since paths should be valid UTF-8.


72-72: LGTM! Proper header value conversion.

Converting byte slices to strings for header values is required as http.Header operates with strings. This maintains compatibility with Go's HTTP package while allowing internal byte-based storage.


95-96: LGTM! Simplified flusher implementation.

The new flusher implementation is more idiomatic and efficient, using type assertion instead of the deprecated http.NewResponseController.

.github/workflows/linters.yml (1)

21-21: Verify golangci-lint v1.62 changelog.

The linter version upgrade from v1.61 to v1.62 may introduce new checks or changes in existing ones.

Please check the changelog at https://github.com/golangci/golangci-lint/releases/tag/v1.62.0 to ensure compatibility with the codebase.

.github/workflows/linux.yml (1)

20-20: Consider deferring PHP 8.4 upgrade.

Using PHP 8.4 in the test matrix might be premature as it's currently in alpha/development stage. This could potentially lead to CI instability.

Let's verify the current status of PHP 8.4:

tests/go.mod (2)

84-84: Verify API version compatibility with non-UTF-8 payload changes.

The update to roadrunner-server/api/v4 v4.18.1 should be verified to ensure it contains the necessary changes for supporting non-UTF-8 payloads.

Let's check the changelog and related commits:

✅ Verification successful

API update is aligned with non-UTF-8 payload handling

The update to v4.18.1 introduces necessary changes for handling non-UTF-8 payloads by switching to byte-based values in the HTTP protocol implementation. This version bump is appropriate and required for the PR's objective.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check changelog and commits for the API update
# Get the changelog or commit history between v4.17.0 and v4.18.1
gh api repos/roadrunner-server/api/compare/v4.17.0...v4.18.1 --jq '.commits[].commit.message'

Length of output: 476


Line range hint 1-1: Request core implementation files.

The current files show only peripheral changes (PHP version update and API dependency bump). To properly review the non-UTF-8 payload handling fix, please provide the core implementation files where the actual changes for handling non-UTF-8 payloads are made.

Let's check for related files:

go func() {
err = hs.ListenAndServe()
if err != nil && !errors.Is(http.ErrServerClosed, err) {
if err != nil && !errors.Is(err, http.ErrServerClosed) {
Copy link

Choose a reason for hiding this comment

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

💡 Codebase verification

Multiple instances of incorrect error comparison order found

The argument order in errors.Is and stderr.Is calls should be fixed across the codebase. The error being checked should be the first argument, followed by the target error.

Locations needing fixes:

  • tests/handler_test.go: Multiple instances of errors.Is(http.ErrServerClosed, err)
  • tests/uploads_test.go: Multiple instances of errors.Is(http.ErrServerClosed, errL)
  • servers/fcgi/fcgi.go: Two instances of stderr.Is(err, http.ErrServerClosed)
  • servers/http11/http.go: Two instances of stderr.Is(err, http.ErrServerClosed)
  • servers/https/https.go: Three instances of stderr.Is(err, http.ErrServerClosed)
🔗 Analysis chain

Fixed incorrect error comparison order.

The change corrects the argument order in errors.Is(). The error being checked should be the first argument, followed by the target error.

Let's check if this issue exists elsewhere in the codebase:

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Search for potentially incorrect error comparisons
ast-grep --pattern 'errors.Is($target, $err)' | grep -v 'errors.Is(err,'

Length of output: 74


Script:

#!/bin/bash
# Search for all errors.Is usage with context
rg "errors\.Is\(" -A 2 -B 2

# Also search for any potential type assertions or comparisons with error types
rg "ErrServerClosed" -A 2 -B 2

Length of output: 17665

@rustatian rustatian merged commit cd7bf49 into master Jan 13, 2025
6 checks passed
@rustatian rustatian deleted the fix/use-bytes-for-proto branch January 13, 2025 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[🐛 BUG]: marshal_payload: string field contains invalid UTF-8

1 participant