Skip to content

Hangs for async custom completions #852

@rgoldberg

Description

@rgoldberg

The implementation of async custom completions using DispatchSemaphore from #782 worked for me in the past, but async custom completions are hanging for me now, presumably due to deadlocks.

I don't know what caused the difference in behavior. I don't know if the hangs:

  1. always existed under certain circumstances (& my current code is experiencing them while my older code didn't)
  2. are caused by subsequent modifications to the async custom completion implementation
  3. are caused by a newer Swift compiler, Swift runtime, and/or macOS
  4. etc.

I'll try to whittle down a concise hang & non-hang examples in the future.

I have a local branch that fixes this that I can submit as a PR; it replaces DispatchSemaphore with async/await all the way down, so it only works for AsyncParsableCommand.

I can reinstate the DispatchSemaphore implementation in place for ParsableCommand if it still works for some async custom completions, or remove it if it no longer works at all (my current local branch does the latter, since it was simpler to investigate & implement that way, but it shouldn't be hard to reinstate the DispatchSemaphore implementation).

I'll investigated more (& potentially get feedback here), provide examples, clean up my local branch, and submit it as a PR.

ArgumentParser version:

main

Swift version:

swift-driver version: 1.127.14.1 Apple Swift version 6.2.3 (swiftlang-6.2.3.3.21 clang-1700.6.3.2)
Target: arm64-apple-macosx26.0

Checklist

  • If possible, I've reproduced the issue using the main branch of this package
  • I've searched for existing GitHub issues

Steps to Reproduce

Will provide a concise example in the future.

Expected behavior

Async custom completion returns instead of hanging.

Actual behavior

Async custom completion hangs instead of returning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions