Skip to content

Barrier hangs indefinitely when arg parties < 0 or invalid type #121474

Closed

Description

@pygeek

Bug report

Bug description:

threading.Barrier at no point checks for valid parties. parties, of a negative value, or invalid type hang indefinitely on .wait(). This behavior is inconsistent from the behavior of any other threading primitives, which either conduct sanity checks on args during initialization, or fail at some point in their execution.

Steps to reproduce:

from threading import Barrier
# negative
barrier = Barrier(-1) # <threading.Barrier at 0x10aa789b0: waiters=0/-1>
barrier.wait()

# invalid type string
barrier = Barrier("test") # <threading.Barrier at 0x10ae64980: waiters=0/test>
barrier.wait()

# invalid type float
barrier = Barrier(0.5) # <threading.Barrier at 0x10aa7a570: waiters=0/0.5>
barrier.wait()

# invalid type object
barrier = Barrier(object()) # <threading.Barrier at 0x10ae4f500: waiters=0/<object object at 0x10a878730>>
barrier.wait()

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    on Jul 8, 2024
  2. changed the title [-]Barrier hangs indefinitely when arg `parties` < 0[/-] [+]Barrier hangs indefinitely when arg `parties` < 0 or invalid type[/+] on Jul 8, 2024
  3. added 2 commits that reference this issue on Jul 8, 2024
  4. graingert commented on Jul 8, 2024

    @graingert
    Contributor
  5. pygeek commented on Jul 8, 2024

    @pygeek
    ContributorAuthor
  6. graingert commented on Jul 8, 2024

    @graingert
    Contributor

    https://github.com/python/cpython/blob/3.12/Lib/asyncio/locks.py#L457

    This issue is not related to async.Barrier. This is a bug in threading.Barrier

    https://github.com/python/cpython/blob/3.12/Lib/threading.py#L670

    I'm aware. My point is that asyncio.Barrier has this validation so threading.Barrier should have it also

  7. added 7 commits that reference this issue on Jul 8, 2024
  8. added a commit that references this issue on Jul 30, 2024
  9. added 2 commits that reference this issue on Jul 30, 2024
  10. added 2 commits that reference this issue on Jul 30, 2024
  11. added a commit that references this issue on Aug 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions