-
-
Notifications
You must be signed in to change notification settings - Fork 638
Fix failing rspec test for non hydrated streamed page #1892
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
Fix failing rspec test for non hydrated streamed page #1892
Conversation
WalkthroughThe HTTPX retries plugin configuration in the request module was enhanced to use a block form that adds a retry_after handler. This handler logs error messages and truncated request bodies, then returns nil to trigger retries. No behavioral changes to retry mechanisms or timeouts; existing options remain unchanged. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 passed)
✨ Finishing touches
🧪 Generate unit tests (beta)
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 |
Code Review - PR #1892: Fix failing rspec test for non hydrated streamed pageSummaryThis PR removes a ✅ Positive Aspects
🔍 Issues & Concerns1. Missing PR Description (Critical)The PR body still contains placeholder text and hasn't been filled out. Please provide:
2. Incomplete Checklist (Critical)All checklist items are unchecked:
Required actions:
3. Inconsistent Error Logging (Medium)There's another similar console.error('Error transforming RSC stream:', error);Questions:
4. Missing Context in Commit Messages (Low)The commit message "remove error log during rsc generation error handling" could be more descriptive:
🧪 Testing Concerns
📋 Action ItemsBefore merging:
💡 Recommendations
⚖️ Overall AssessmentConditionally approve pending required changes The code change itself is reasonable and targeted, but the PR lacks essential context and documentation. The removal of Recommendation: Request changes to complete the PR checklist and add proper documentation before merging. |
Code Review: Fix failing rspec test for non hydrated streamed pageSummaryThis PR removes a Positive Aspects✅ Error state tracking preserved: The change correctly maintains the error handling logic - ✅ Conditional error emission intact: The ✅ Minimal, focused change: Single-line removal reduces risk Issues & Concerns1. Inconsistency with Similar Code
|
Code Review - PR #1892: Fix failing rspec test for non hydrated streamed pageSummaryThis PR removes a Code Quality & Best Practices ✅Positive aspects:
Concerns:
Recommendations
Test Coverage
|
This reverts commit 3f091dd1ac02c0b00c66d9580d63b11fa2c73746.
Code Review: Fix failing rspec test for non hydrated streamed pageSummaryThis PR removes a AnalysisWhat the code does:The
Code Quality: ✅ GoodPositive aspects:
Potential concerns:
Recommendations1. Consider conditional logging (Optional Enhancement)Instead of removing the log entirely, consider making it conditional: const reportError = (error: Error) => {
if (throwJsErrors) {
console.error('Error in RSC stream', error);
emitError(error);
}
renderState.hasErrors = true;
renderState.error = error;
};This maintains observability when errors are being thrown while reducing noise in test scenarios. 2. PR Checklist ItemsThe PR description mentions these items are unchecked:
Suggestions:
3. Test Coverage AnalysisLooking at
Missing test coverage:
Consider adding a test like: test('errors are handled without console logging', async () => {
const consoleErrorSpy = jest.spyOn(console, 'error');
// ... render component that triggers an error with throwJsErrors: false
expect(consoleErrorSpy).not.toHaveBeenCalledWith('Error in RSC stream', expect.any(Error));
consoleErrorSpy.mockRestore();
});Potential Issues:
|
2e2c532 to
f8d1dbc
Compare
Code ReviewThank you for this PR! I've reviewed the changes and have some feedback below. OverviewThis PR addresses a failing RSpec test for non-hydrated streamed pages by making three key changes:
Detailed Feedback✅ Positive Changes1. Removal of console.error (ReactOnRailsRSC.ts:58)
2. Regex fix in package.json test script
|
Code Review for PR #1892: Fix failing rspec test for non hydrated streamed pageSummaryThis PR makes three key changes:
Detailed Review1. Code Quality & Best Practices✅ Positive:
Recommendation: Consider adding a conditional console.error for development environments: const reportError = (error: Error) => {
if (throwJsErrors) {
emitError(error);
} else if (process.env.NODE_ENV !== 'production') {
console.error('Error in RSC stream', error);
}
renderState.hasErrors = true;
renderState.error = error;
};2. Configuration Changes (react_on_rails_pro.rb)The timeout and retry changes appear to be test-specific workarounds rather than proper fixes: # Before
config.ssr_timeout = 10
config.renderer_request_retry_limit = 1
# After
config.renderer_http_pool_timeout = 20
config.ssr_timeout = 30
config.renderer_request_retry_limit = 0Issues:
Questions:
Recommendation:
3. Test Coverage❌ Missing:
Questions:
Recommendation:
4. Performance Considerations
Recommendation:
5. Security Concerns✅ No security issues identified
6. Documentation & Process Issues❌ Missing:
7. Potential Bugs🔍 Worth investigating:
Recommendations SummaryHigh Priority:
Medium Priority: Low Priority: Questions for the Author
ConclusionWhile the regex fix is good and the intent to reduce console noise is valid, the configuration changes appear to be treating symptoms rather than addressing root causes. This PR needs:
Status: Review generated with assistance from Claude Code |
Code Review: PR #1892 - Fix failing rspec test for non hydrated streamed pageOverviewThis PR makes several changes to fix a failing rspec test related to non-hydrated streamed pages. The changes span timeout configurations, error logging, and test patterns. 🔴 Critical Issues1. Hardcoded Timeout Values in Production Code (request.rb:247-253)The most concerning change is hardcoding ALL timeout values to 100 seconds in timeout: {
connect_timeout: 100,
read_timeout: 100,
write_timeout: 100,
request_timeout: 100,
operation_timeout: 100,
keep_alive_timeout: 100,
}Issues:
This appears to be debug/test code that shouldn't be committed to production. Recommendation: Revert to using configuration values: timeout: {
connect_timeout: ReactOnRailsPro.configuration.renderer_http_pool_timeout,
read_timeout: ReactOnRailsPro.configuration.ssr_timeout,
# ... other timeouts based on appropriate config values
}2. Incomplete PR ChecklistThe PR description still contains template placeholders and all checklist items are unchecked:
Per CLAUDE.md requirements, these MUST be completed before merging.
|
Code Review for PR #1892Thank you for this PR! I've reviewed the changes and have several concerns and suggestions: 🚨 Critical Issues1. Hardcoded Timeout Values (request.rb:247-252)The changes replace configurable timeout values with hardcoded timeout: {
connect_timeout: 100,
read_timeout: 100,
write_timeout: 100,
request_timeout: 100,
operation_timeout: 100,
keep_alive_timeout: 100,
}Problems:
Recommendation: This should use the configuration values properly: timeout: {
connect_timeout: ReactOnRailsPro.configuration.renderer_http_pool_timeout,
read_timeout: ReactOnRailsPro.configuration.ssr_timeout,
write_timeout: ReactOnRailsPro.configuration.ssr_timeout,
request_timeout: ReactOnRailsPro.configuration.ssr_timeout,
# ... etc
}2. Missing PR DescriptionThe PR body still contains placeholder text and doesn't explain:
Required: Please provide:
|
Pull Request ReviewSummaryThis PR addresses a failing RSpec test for non-hydrated streamed pages by making several configuration and error handling adjustments. The changes focus on reducing noise in console output and adjusting timeout/retry settings for better test reliability. Code Quality & Best Practices✅ Good Practices:
|
Pull Request Review - PR #1892Thank you for working on fixing the failing RSpec test! I've reviewed the changes and have several concerns and recommendations: Critical Issues1. Hardcoded Timeout Values in Production CodeLocation: react_on_rails_pro/lib/react_on_rails_pro/request.rb:256-262 All timeout values are hardcoded to 100 seconds, completely ignoring the configuration values. This overrides ReactOnRailsPro.configuration.renderer_http_pool_timeout and will mask real timeout issues. This appears to be a debugging workaround that shouldn't be committed. Recommendation: Either use the configuration values properly or create new configuration options if needed. 2. Disabled Retry Logic Without Clear JustificationLocation: react_on_rails_pro/spec/dummy/config/initializers/react_on_rails_pro.rb:39 Changed from renderer_request_retry_limit = 1 to 0, disabling retries entirely. The PR description mentions an EOFError but doesn't explain why disabling retries fixes it. This may mask the underlying connection issue. Recommendation: Investigate the root cause of the EOF error instead of disabling retries. 3. Overly Verbose Retry LoggingLocation: react_on_rails_pro/lib/react_on_rails_pro/request.rb:233-237 The retry callback logs at ERROR level for every retry attempt and logs request bodies which could expose sensitive data. Has typo: occured should be occurred. The lambda always returns 0 which could cause infinite retry loops without max_retries. Recommendation: Use appropriate log levels and add max_retries configuration. Moderate Issues4. Removed Error Logging in Critical PathLocation: packages/react-on-rails-pro/src/ReactOnRailsRSC.ts:57-63 Removed console.error from the error handler, reducing error visibility. Debugging stream-related issues will be harder. Recommendation: Consider environment-based conditional logging instead of removing it entirely. 5. Test Configuration ChangesLocation: react_on_rails_pro/spec/dummy/config/initializers/react_on_rails_pro.rb Multiple timeout configurations changed without clear explanation of why these specific values were chosen or whether they should apply to production. Good Changes6. Fixed Test Path PatternLocation: packages/react-on-rails-pro/package.json:11 Changed from .(.rsc.test.). to ..rsc.test.. - This properly escapes the dots in the regex pattern. Good fix! Missing Information
Recommendations SummaryBefore merging:
Alternative approach: Investigate if the EOF error is caused by connection pooling issues, stream handling problems in the test environment, or race conditions in cleanup code. These changes feel like they're working around symptoms rather than fixing root causes. Let me know if you'd like help investigating the root cause! |
Code Review for PR #1892Summary: This PR addresses an EOFError by making timeout/retry configuration changes and removing error logging. However, there are several critical concerns. Critical Issues1. Hardcoded Timeout Values (BLOCKING) - react_on_rails_pro/lib/react_on_rails_pro/request.rb:256-263 2. Debug Code in Production (BLOCKING) - react_on_rails_pro/lib/react_on_rails_pro/request.rb:234-239 3. Silenced Error Logging - packages/react-on-rails-pro/src/ReactOnRailsRSC.ts:57-63 4. Disabled Retries in Tests - config/initializers/react_on_rails_pro.rb:39 Other Concerns
Questions
RecommendationRequest changes. The hardcoded timeouts and debug logging are blocking issues. Please clarify root cause and provide a more targeted fix that uses configuration properly. Note: The regex fix in package.json is good but appears unrelated to the bug fix. |
There was a problem hiding this 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)
react_on_rails_pro/lib/react_on_rails_pro/request.rb (1)
257-263: Consider using configuration values instead of hardcoded timeouts.All timeout values are hardcoded to 100 seconds, which removes the ability to configure timeouts dynamically per environment. This is inconsistent with the gem's configuration pattern used elsewhere (e.g.,
renderer_http_pool_sizeat line 249).Note that the error message handler at lines 268-270 still references
renderer_http_pool_timeout, creating an inconsistency.Consider using configuration values:
timeout: { - connect_timeout: 100, - read_timeout: 100, - write_timeout: 100, - request_timeout: 100, - operation_timeout: 100, - keep_alive_timeout: 100, + connect_timeout: ReactOnRailsPro.configuration.renderer_connect_timeout, + read_timeout: ReactOnRailsPro.configuration.renderer_read_timeout, + write_timeout: ReactOnRailsPro.configuration.renderer_write_timeout, + request_timeout: ReactOnRailsPro.configuration.renderer_request_timeout, + operation_timeout: ReactOnRailsPro.configuration.renderer_operation_timeout, + keep_alive_timeout: ReactOnRailsPro.configuration.renderer_keep_alive_timeout, }If hardcoded values are intentional for this PR to fix the failing test, consider adding a TODO comment explaining the rationale and plan for making these configurable in the future.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
react_on_rails_pro/lib/react_on_rails_pro/request.rb(2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
{Gemfile,Rakefile,config.ru,**/*.{rb,rake,gemspec,ru}}
📄 CodeRabbit inference engine (CLAUDE.md)
{Gemfile,Rakefile,config.ru,**/*.{rb,rake,gemspec,ru}}: All Ruby code must pass RuboCop with zero offenses before commit/push
RuboCop is the sole authority for Ruby file formatting; never manually format Ruby files
Files:
react_on_rails_pro/lib/react_on_rails_pro/request.rb
🧠 Learnings (1)
📓 Common learnings
Learnt from: alexeyr-ci
Repo: shakacode/react_on_rails PR: 1644
File: node_package/src/ReactOnRailsRSC.ts:87-87
Timestamp: 2024-12-12T13:07:09.929Z
Learning: When handling errors in 'node_package/src/ReactOnRailsRSC.ts', include the error stack in error messages in development and test environments to aid debugging.
| retry_after: ->(req, res) do | ||
| Rails.logger.error("An error occured and retry is going to be made") | ||
| Rails.logger.error("Error: #{res.error}") | ||
| Rails.logger.error("Request Body: #{req.body}") | ||
| 0 | ||
| end, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Avoid logging request body due to security and privacy risks.
The retry_after hook unconditionally logs the full request body, which may contain sensitive information such as rendering code, form data, PII, or secrets. This creates a compliance and security risk.
Additionally, the hook always returns 0 (immediate retry) regardless of the error type, which could cause inappropriate retry behavior for non-transient errors and lacks backoff strategy.
Minor: Line 235 has a typo—"occured" should be "occurred".
Consider these improvements:
retry_after: ->(req, res) do
- Rails.logger.error("An error occured and retry is going to be made")
+ Rails.logger.error("An error occurred and retry is going to be made")
Rails.logger.error("Error: #{res.error}")
- Rails.logger.error("Request Body: #{req.body}")
+ # Avoid logging request body due to potential sensitive data
+ Rails.logger.debug("Request path: #{req.path}") if Rails.env.development?
0
end,Also, consider implementing conditional retry logic based on error type (e.g., only retry on transient errors like connection failures, not on 4xx client errors).
📝 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.
| retry_after: ->(req, res) do | |
| Rails.logger.error("An error occured and retry is going to be made") | |
| Rails.logger.error("Error: #{res.error}") | |
| Rails.logger.error("Request Body: #{req.body}") | |
| 0 | |
| end, | |
| retry_after: ->(req, res) do | |
| Rails.logger.error("An error occurred and retry is going to be made") | |
| Rails.logger.error("Error: #{res.error}") | |
| # Avoid logging request body due to potential sensitive data | |
| Rails.logger.debug("Request path: #{req.path}") if Rails.env.development? | |
| 0 | |
| end, |
🤖 Prompt for AI Agents
In react_on_rails_pro/lib/react_on_rails_pro/request.rb around lines 234–239,
the retry_after hook currently logs the full request body (a security/privacy
risk), has a typo ("occured"), and always returns 0 (immediate retry) regardless
of error type; change it to stop logging req.body and instead log non-sensitive
metadata (e.g., request path, method, and sanitized headers) and the error
message/class, correct the typo to "occurred", and implement conditional
retry/backoff: inspect the response/error (status code or exception class) and
only return a retry delay for transient errors (e.g., network/5xx) — use an
exponential backoff strategy (or nil/false for no retry) for non-transient
errors such as 4xx client errors.
PR Review: Fix failing rspec test for non hydrated streamed pageSummaryThis PR aims to fix an Code Quality & Best Practices✅ Positive Changes
|
This reverts commit 98e0075.
Code Review for PR #1892Thank you for working on fixing the failing rspec test issue. I've reviewed the changes and have comprehensive feedback. 🔴 Critical Issues1. Typo in Error Message (react_on_rails_pro/lib/react_on_rails_pro/request.rb:235) Line has: 2. Unclear Purpose and Incomplete Implementation The PR references issue #1895 about "body duplication problem" but:
Questions:
|
|
|
5. Code Quality: Undocumented Magic Behavior The retry_after lambda has undocumented behavior. Issues:
Recommendation: Add inline comment explaining the httpx retry_after callback contract (when it is invoked, what return values mean, etc.) |
📋 Minor Issues6. Inconsistent Error Logging Pattern Looking at the codebase, most error logging uses multi-line messages or heredoc for clarity. Consider consolidating the three separate logger.error calls into one heredoc-style message with the [ReactOnRailsPro] prefix for consistency. 🔧 Required Actions Before Merge
|
📚 Documentation SuggestionsThe retry_after callback is not obvious to readers. Consider adding documentation:
✅ What is Good
Overall Assessment: This PR needs more work before merging. The core idea of adding retry visibility is good, but the implementation has security concerns, missing tests, and unclear purpose. Please address the critical issues and complete the PR checklist. Let me know if you need help with any of these items! |
Code Review: Fix failing rspec test for non hydrated streamed pageThank you for working on this fix! I've reviewed the changes and have several observations and concerns: Critical Issues1. Typo in Error MessagesAll three error log messages contain a typo: "occured" should be "occurred" Lines: 115, 238 2. Missing Newlines at End of FileAction Required: Add a newline at the end of 3. Incomplete PR DescriptionThe PR description references issue #1895, but that issue template appears incomplete/not filled out. This makes it difficult to understand:
Code Quality Issues4. Debug Logging in Production CodeThe changes add error-level logging for debugging purposes, but these will run in production: Rails.logger.error("An error occured and react on rails retry is going to be made")
Rails.logger.error("Error: #{e}")
Rails.logger.error("Post Options: #{post_options}")Concerns:
Recommendation:
5. Lambda Callback Side EffectsThe retry_after: ->(req, res) do
Rails.logger.error("An error occured and retry is going to be made")
Rails.logger.error("Error: #{res.error}")
Rails.logger.error("Request Body: #{req.body&.to_s.first(1000)}")
nil
end,Concerns:
6. Potential Body Duplication IssueThe PR title mentions "Fix the body duplication problem when a retry happen after a connection error" (issue #1895), but the code changes only add logging. There's no actual fix for body duplication visible in these changes. Question: How does adding logging fix the body duplication issue? Is this PR incomplete? Testing Concerns7. No Test CoverageThe PR checklist shows:
None of these are checked, yet the PR claims to fix a failing test. Where are:
Performance Considerations8. String Conversion on Every Retry
Security Concerns9. Logging Sensitive InformationBoth retry handlers log request/response data that could contain:
Recommendation: Implement log sanitization or redaction for sensitive fields. Recommendations
Questions for Author
Before merging:
|
|
Closed after reaching the results posted at the description and will be solved after fixing theis issue |
Summary
Cause of the error
The error happens because of the following bug:
ConnectionTimeoutor adescriptor closederror.retriesplugin at HTTPx retries to make the request again.request.rbfile is executed instead of the HTTPx retry logic.The exact scenario happens at the failing test
To check the error that happens and cause HTTPx retry plugin to retry the request, I wrote the following code at the code that initiates the HTTPx object
It logs the error that happens and causes the retry to happen. And by checking the testing log file here. I found that the error happens is
Which happens for no specific reason, I already increased all timeout values at HTTPx side by setting the following configs
And at Fastify side, I added the following:
And the same error still happens. It's planned to reproduce the error outside React on Rails and check if it's a problem at HTTPx or at Fastify and report the issue then. However, when the HTTPx
retriesplugin is removed, the error disappears, which makes us suspect that the problem is at HTTPx.Reproduce the problem locally
To reproduce the problem locally, try opening a streaming page that takes too long to render and causes a
Timeouterror. You can try to openhttp://localhost:3000/rsc_posts_page_over_redis?artificial_delay=3000page, and you can see that the page content is repeated twice before redirecting you to the500error page. At the CI test, the page is not redirected to the500error page, because at the second trial to SSR the page, noTimeouterror happens.You can try to reproduce it locally by adding a code like this to the
RSCPageComponentThis change is