GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix a race in `click.testing.StreamMixer`'s finalization, seen in a multi-threaded context by neutrinoceros · Pull Request #2991 · pallets/click

Conversation

@neutrinoceros

@neutrinoceros neutrinoceros commented Jul 4, 2025 •
edited by Rowlando13
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

xref python/cpython#136248
xref neutrinoceros/inifix#421

The reproducer I used to work on this involves typer and multi-threading, and isn't consistently failing: I originally only hit the race about once in 10k tries, so this seems difficult to test systematically.
I also am not sure this rare bug warrents an entry in CHANGES.rst, but I'm glad to add it if needed.

update: scratch that, this is a similar looking but different error. My patch doesn't fix the reproducer from #824 (comment)

update 2: close #2993

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@neutrinoceros
neutrinoceros marked this pull request as ready for review July 4, 2025 10:24
neutrinoceros
neutrinoceros commented Jul 4, 2025
View reviewed changes
Comment thread tests/test_testing.py
with runner.isolation() as (_, err, _):
click.echo("\udce2", err=True, nl=False)

assert err.getvalue() == b"\\udce2"

@neutrinoceros neutrinoceros Jul 4, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

With my patch, stream objects yielded from runner.isolation, including err, may be closed as the context manager exits, dereferencing (hence, allowing gc to collect) its internal StreamMixer reference. Comparable tests already do it this way, so I'm hoping that this change is acceptable.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@neutrinoceros
neutrinoceros force-pushed the bug/testing-thread-safety branch 2 times, most recently from 345e42b to 30bb693 Compare July 4, 2025 12:51
@neutrinoceros
neutrinoceros changed the base branch from main to stable July 4, 2025 12:51
@neutrinoceros
neutrinoceros force-pushed the bug/testing-thread-safety branch from 30bb693 to 712f3f4 Compare July 4, 2025 12:52
@neutrinoceros neutrinoceros mentioned this pull request Jul 4, 2025
TST: flakiness in test sessions on free-threaded CPython 3.14.0b2 neutrinoceros/inifix#421
Closed
@davidism davidism changed the title BUG/TST: fix a race in click.testing.StreamMixer's finalization, seen in a multi-threaded context fix a race in click.testing.StreamMixer's finalization, seen in a multi-threaded context Jul 4, 2025
neutrinoceros added 2 commits July 5, 2025 09:26
@neutrinoceros
BUG/TST: fix a race in click.testing.StreamMixer's finalization, se…
e37cad2
…en in a multi-threaded context
@neutrinoceros
TST: adjust tests
4679b1c
@neutrinoceros
neutrinoceros force-pushed the bug/testing-thread-safety branch from 712f3f4 to 4679b1c Compare July 5, 2025 07:27
@Rowlando13
Rowlando13 deleted the branch pallets:stable July 16, 2025 06:23
@Rowlando13 Rowlando13 closed this Jul 16, 2025
@Rowlando13 Rowlando13 reopened this Jul 16, 2025
@kdeldycke

kdeldycke commented Jul 19, 2025

Copy link
Copy Markdown
Collaborator

Looks reasonable to me to be merge as-is: as @neutrinoceros pointed out, this is hard to constantly reproduce in unit tests (which should probably be named stress tests in that case), and I doubt lots of Click users are running the code in an intensive multi-threaded context as @neutrinoceros does. So if this PR is breaking anything, we would have already caught the regression.

neutrinoceros reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@neutrinoceros

neutrinoceros commented Jul 19, 2025

Copy link
Copy Markdown
Contributor Author

I just noticed I accidentally linked #824, but again, my patch doesn't actually fix it, so it should be undone before merge.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke kdeldycke added the bug label Jul 21, 2025
@kdeldycke kdeldycke added this to the 8.2.2 milestone Jul 21, 2025
@Rowlando13

Rowlando13 commented Jul 22, 2025 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Member

@neutrinoceros Can you unlink #824. For some reason I cannot. Once you do that I will hit merge.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@neutrinoceros

neutrinoceros commented Jul 22, 2025

Copy link
Copy Markdown
Contributor Author

Weird. It seems I also can't.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Rowlando13

Rowlando13 commented Jul 22, 2025

Copy link
Copy Markdown
Member

@kdeldycke can you give it a try?

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@kdeldycke

kdeldycke commented Jul 22, 2025

Copy link
Copy Markdown
Collaborator

@kdeldycke can you give it a try?

Blocked for me to:

Screenshot 2025-07-22 at 12 01 14

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@Rowlando13
Rowlando13 merged commit 737bfbd into pallets:stable Jul 22, 2025
@neutrinoceros
neutrinoceros deleted the bug/testing-thread-safety branch July 22, 2025 10:32
neutrinoceros added a commit to neutrinoceros/click that referenced this pull request Jul 22, 2025
@neutrinoceros
add missing changelog entry for PR pallets#2991
b87b337
@neutrinoceros neutrinoceros mentioned this pull request Jul 22, 2025
add missing changelog entry for PR #2991 #3009
Merged
Rowlando13 added a commit that referenced this pull request Jul 23, 2025
@Rowlando13
add missing changelog entry for PR #2991 (#3009)
c88f333
@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Aug 6, 2025
@kdeldycke kdeldycke added the test runner CliRunner and Click's test utilities feature label Feb 28, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Reviewers

No reviews

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

test runner CliRunner and Click's test utilities feature

Projects

None yet

Milestone

8.2.2

Development

Successfully merging this pull request may close these issues.

a race condition in click.testing.StreamMixer's finalization ValueError: I/O operation on closed file in testing

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@neutrinoceros @kdeldycke @Rowlando13
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.