Skip to content

[Fix #3228] idle-timeout not working in cluster mode (#3235)#7

Open
MitchLewis930 wants to merge 1 commit intopr_057_beforefrom
pr_057_after
Open

[Fix #3228] idle-timeout not working in cluster mode (#3235)#7
MitchLewis930 wants to merge 1 commit intopr_057_beforefrom
pr_057_after

Conversation

@MitchLewis930
Copy link
Copy Markdown

@MitchLewis930 MitchLewis930 commented Jan 30, 2026

User description

PR_057


PR Type

Bug fix, Tests


Description

  • Fix idle-timeout not working in cluster mode by signaling master process

  • Add idle_timeout_reached flag to track timeout state in server

  • Add integration tests for idle timeout in cluster and single modes

  • Minor typo fix in comment and formatting improvements


Diagram Walkthrough

flowchart LR
  A["Worker Process"] -->|idle timeout detected| B["Set idle_timeout_reached flag"]
  B -->|in cluster mode| C["Send SIGTERM to master"]
  C -->|triggers shutdown| D["Server stops accepting connections"]
  E["Integration Tests"] -->|verify timeout| D
Loading

File Walkthrough

Relevant files
Bug fix
worker.rb
Signal master on idle timeout in cluster                                 

lib/puma/cluster/worker.rb

  • Add signal to master process when idle timeout is reached in cluster
    mode
  • Kill master with SIGTERM to trigger proper shutdown sequence
+2/-0     
server.rb
Add idle timeout reached flag to server                                   

lib/puma/server.rb

  • Add idle_timeout_reached attribute reader to track timeout state
  • Initialize @idle_timeout_reached flag to false in constructor
  • Set flag to true when IO.select times out and not shutting down
  • Improve code formatting with blank lines for readability
+9/-1     
Documentation
runner.rb
Fix typo in control server comment                                             

lib/puma/runner.rb

  • Fix typo in comment: 'aand' to 'and'
+1/-1     
Tests
test_integration_cluster.rb
Add idle timeout test for cluster mode                                     

test/test_integration_cluster.rb

  • Add test_idle_timeout test for cluster mode with multiple workers
  • Verify server stops accepting connections after idle timeout expires
  • Test uses 1 second idle timeout and validates connection refusal
+14/-0   
test_integration_single.rb
Add idle timeout test for single mode                                       

test/test_integration_single.rb

  • Add test_idle_timeout test for single server mode
  • Verify server stops accepting connections after idle timeout expires
  • Test uses 1 second idle timeout and validates connection refusal
+12/-0   

@qodo-code-review
Copy link
Copy Markdown

PR Compliance Guide 🔍

Below is a summary of compliance checks for this PR:

Security Compliance
🟢
No security concerns identified No security vulnerabilities detected by AI analysis. Human verification advised for critical code.
Ticket Compliance
🎫 No ticket provided
  • Create ticket/issue
Codebase Duplication Compliance
Codebase context is not defined

Follow the guide to enable codebase context checks.

Custom Compliance
🟢
Generic: Comprehensive Audit Trails

Objective: To create a detailed and reliable record of critical system actions for security analysis
and compliance.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Error Handling

Objective: To prevent the leakage of sensitive system information through error messages while
providing sufficient detail for internal debugging.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Secure Logging Practices

Objective: To ensure logs are useful for debugging and auditing without exposing sensitive
information like PII, PHI, or cardholder data.

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Security-First Input Validation and Data Handling

Objective: Ensure all data inputs are validated, sanitized, and handled securely to prevent
vulnerabilities

Status: Passed

Learn more about managing compliance generic rules or creating your own custom rules

🔴
Generic: Meaningful Naming and Self-Documenting Code

Objective: Ensure all identifiers clearly express their purpose and intent, making code
self-documenting

Status:
Boolean naming: The new boolean flag idle_timeout_reached does not follow the preferred boolean naming
convention (e.g., is_/has_), reducing self-documentation clarity.

Referred Code
attr_reader :idle_timeout_reached

Learn more about managing compliance generic rules or creating your own custom rules

Generic: Robust Error Handling and Edge Case Management

Objective: Ensure comprehensive error handling that provides meaningful context and graceful
degradation

Status:
Unhandled kill failure: The added Process.kill "SIGTERM", master call is not guarded against failures
(e.g., Errno::ESRCH, Errno::EPERM, or invalid master PID), which can raise during shutdown
and cause an ungraceful worker exit without contextual handling.

Referred Code
  Process.kill "SIGTERM", master if server.idle_timeout_reached
ensure

Learn more about managing compliance generic rules or creating your own custom rules

Compliance status legend 🟢 - Fully Compliant
🟡 - Partial Compliant
🔴 - Not Compliant
⚪ - Requires Further Human Verification
🏷️ - Compliance label

@qodo-code-review
Copy link
Copy Markdown

PR Code Suggestions ✨

Explore these optional code suggestions:

CategorySuggestion                                                                                                                                    Impact
Possible issue
Guard and rescue master kill

To prevent redundant signals and handle errors, send the SIGTERM signal to the
master only once and rescue Errno::ESRCH in case the master process has already
been terminated.

lib/puma/cluster/worker.rb [150]

-Process.kill "SIGTERM", master if server.idle_timeout_reached
+if server.idle_timeout_reached && !@idle_sig_sent
+  begin
+    Process.kill "SIGTERM", master
+    @idle_sig_sent = true
+  rescue Errno::ESRCH
+    # master already terminated
+  end
+end
  • Apply / Chat
Suggestion importance[1-10]: 7

__

Why: The suggestion correctly identifies a potential race condition where multiple workers might signal the master, and adds robust error handling to prevent an Errno::ESRCH exception if the master process is already gone.

Medium
  • More

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants