Works with the AI tools you already use

    CClaude CodeCCursorCCodex CLIGGitHub CopilotGGemini CLI+17 more

    Repair Semaphore Permit Leaks

    by Mariusz Wrzeszczynski

    1

    Repair semaphore permit leaks and over-release bugs across exceptions, cancellation, timeouts, task submission, and shutdown.

    Secure checkout via Stripe

    0 installsSecurity scanned

    See it in action

    You say

    Our Java ingestion service acquires a fair Semaphore before submitting work to an ExecutorService. If execute() rejects the task or cancellation wins before the worker starts, the callback that normally releases the permit never runs. After repeated deploy drains, all permits disappear and new requests block. Repair locally with a fake executor and deterministic barriers. Preserve the permit count, fairness, queue policy, timeout values, and retry behavior; do not touch production workers.

    Your agent does

    Permit leak found. The request acquires before task submission, but executor rejection bypasses the callback that normally releases it. The repair assigns ownership immediately after successful acquire, transfers it only after accepted submission, funnels all terminal paths through one guarded release, and validates rejection, cancellation, timeout, and duplicate-cleanup orderings with deterministic barriers.

    What you get

    Eliminate resource exhaustion caused by stranded concurrency permits.Fix race conditions between task cancellation and permit acquisition.Resolve ambiguity in weighted semaphore partial-acquisition failures.Implement deterministic testing for concurrency-related drift.

    About this skill

    The problem

    Concurrency gates often fail silently when semaphores leak permits after exceptions or cancellations. This leads to services that gradually stop accepting work despite having idle resources or, conversely, exceeding configured limits.

    What it does

    • Identifies every semaphore instance and guarded resource across the codebase.
    • Reconstructs permit ownership timelines for success, timeout, and cancellation paths.
    • Repairs acquisition/release symmetry to ensure every permit has exactly one terminal disposition.
    • Fixes partial-failure cleanup in weighted/multi-permit acquisition logic.
    • Implements idempotent, owner-aware release mechanisms without altering business retry logic.

    Why this beats prompting it yourself

    General LLMs often suggest simple try-finally blocks that fail during complex race conditions or async cancellations. This skill uses a strict conservation invariant and permit-ownership registry to ensure logic is mathematically sound across all possible failure states.

    Use cases

    • Fixing services that eventually hang or "freeze" under high load.
    • Ensuring worker pools don't exceed memory limits due to double-releases.
    • Hardening async task submissions where permits are stranded on submission failure.
    • Converting sleep-based race tests into deterministic concurrency barriers.

    Known limitations

    Does not modify global infrastructure settings like external load balancer capacity. Requires repository access to inspect local synchronization primitives.

    How to install

    Drop the file into your AI Agent. Works with Claude, Cursor, ChatGPT, and 20+ more.

    Reviews

    No reviews yet

    Be one of the first to try it. Every listed skill passes our trust checks below.

    Security scanned

    Passed our 8-point scan before listing

    Fresh listing

    Recently published to Agensi

    30-day refund

    Not a fit? Get your money back

    Frequently Asked Questions

    Popular in AI Agents & LLM Ops