Skip to content

Avoid mutating global STDOUT & STDERR (#1837)#1

Open
MitchLewis930 wants to merge 1 commit intopr_051_beforefrom
pr_051_after
Open

Avoid mutating global STDOUT & STDERR (#1837)#1
MitchLewis930 wants to merge 1 commit intopr_051_beforefrom
pr_051_after

Conversation

@MitchLewis930
Copy link

PR_051

@MitchLewis930 MitchLewis930 requested a review from Copilot January 31, 2026 01:27
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR modifies the Puma::Events class to avoid mutating global STDOUT and STDERR objects by duplicating them instead of using the originals directly.

Changes:

  • Updated Puma::Events#initialize to duplicate stdout/stderr arguments instead of using them directly
  • Modified tests to verify that duplicated streams are used and that sync settings are respected
  • Added test setup to ensure test infrastructure can access the duplicated logger outputs

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.

File Description
lib/puma/events.rb Changed to duplicate stdout/stderr arguments to avoid mutating globals
test/test_events.rb Updated assertions to compare inspected strings and added test for sync behavior
test/test_tcp_logger.rb Added instance variable assignment to support test infrastructure

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +26 to +31
def test_stdio_respects_sync
STDOUT.sync = false
events = Puma::Events.stdio

assert !STDOUT.sync
assert events.stdout.sync
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

This test mutates the global STDOUT object by setting sync to false, which could affect other tests. The test should restore the original sync value in an ensure block to prevent side effects on other tests.

Suggested change
def test_stdio_respects_sync
STDOUT.sync = false
events = Puma::Events.stdio
assert !STDOUT.sync
assert events.stdout.sync
def test_stdio_respects_sync
original_sync = STDOUT.sync
STDOUT.sync = false
events = Puma::Events.stdio
assert !STDOUT.sync
assert events.stdout.sync
ensure
STDOUT.sync = original_sync

Copilot uses AI. Check for mistakes.
# in lib/puma/launcher.rb:85
# Puma::Events is default tcp_logger for cluster mode
logger = Puma::Events.new(STDOUT, STDERR)
logger.instance_variable_set(:@stdout, $stdout) # ensure capture_process_io has access to the loggers output
Copy link

Copilot AI Jan 31, 2026

Choose a reason for hiding this comment

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

Corrected spelling of 'loggers' to 'logger's'.

Suggested change
logger.instance_variable_set(:@stdout, $stdout) # ensure capture_process_io has access to the loggers output
logger.instance_variable_set(:@stdout, $stdout) # ensure capture_process_io has access to the logger's output

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants