Skip to content
Back to skills

Async Concurrency

ASecurity

Designs and diagnoses .NET asynchronous and concurrent work, including cancellation, task ownership, synchronization, channels, and race conditions. Use for correctness or throughput under concurrency; do not use for runtime dump/counter investigations alone (use dotnet-diagnostics).

  • 7 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added December 4, 2026
ai-agentstestingcode-reviewapi

Works with

  • api

Security analysis

A100/100

Pro scans all 2 files and shows the line behind each finding

Scanned December 4, 2026

npx -y skills add k4ndev/claude-code-dotnet --skill async-concurrency --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Async Concurrency?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Async Concurrency
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/k4ndev-async-concurrency/badge)](https://www.skillsdirectory.com/skills/k4ndev-async-concurrency)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: async-concurrency
description: Designs and diagnoses .NET asynchronous and concurrent work, including cancellation, task ownership, synchronization, channels, and race conditions. Use for correctness or throughput under concurrency; do not use for runtime dump/counter investigations alone (use dotnet-diagnostics).
---

# Async and Concurrency

## Purpose
Ensure asynchronous work is cancellable, observed, bounded, and safe across its full lifecycle.

## Scope
`Task`, async/await, cancellation, locks, shared state, channels, parallelism, hosted work, and `DbContext` concurrency.

## When to use
- A race, deadlock, starvation, lost update, stuck task, or cancellation bug is described.
- User asks to design background processing or bounded asynchronous work.

## Do not use for
- Collecting runtime traces/dumps/counters without code-level design: use `dotnet-diagnostics`.
- Broker delivery guarantees/outbox design: use `messaging-patterns`.
- EF query tracking/migration behavior: use `efcore-patterns`.

## Required context
Trace task creation/await chain, token source and owner, exception observation, shared mutable state, scheduler/host lifetime, queue limits, and whether side effects have committed.

## Workflow
1. Build a lifecycle graph: creator, owner, cancellation trigger, completion observation, and resource disposal.
2. Find sync-over-async (`.Result`, `.Wait()`, `GetAwaiter().GetResult()`), `async void` (except deliberate event handlers), and unobserved fire-and-forget.
3. Identify synchronization and shared mutable state; never await while holding `lock`; protect invariants, not arbitrary code duration.
4. Propagate `CancellationToken` through cancellable calls. Separate request cancellation from durable post-commit work with explicit ownership/queueing.
5. Bound parallelism, channels, retry loops, and in-flight memory; define overload/backpressure behavior.
6. Do not concurrently use a single EF `DbContext`; create separate units of work if parallelism is required.
7. Test cancellation, concurrent access, queue saturation, exceptions, and shutdown deterministically; use gates/fakes rather than sleeps.

## Decision rules
- Fire-and-forget is acceptable only with a supervising owner that records failures and stops with the host.
- Use `Channel<T>` for producer/consumer work when bounded capacity and backpressure are needed; choose full-mode behavior deliberately.
- `ConfigureAwait(false)` depends on application context and project rules; do not apply blindly to UI code.

## Expected output format
Show task ownership and cancellation path, relevant race/deadlock interleaving, corrected approach, overload/shutdown behavior, and deterministic test cases.

## Common mistakes
- Creating detached tasks, using one context concurrently, unbounded `Task.WhenAll`, swallowing cancellation, or passing request-aborted tokens after a durable commit without a policy.

## Edge cases
- Cancellation is cooperative and does not roll back completed side effects.
- Disposing a `CancellationTokenSource` while consumers still register/use it can race; lifetime must cover all consumers.
- Locks may be correct for short synchronous invariants; async primitives are not automatically faster or safer.

## Examples
See [async examples](examples.md) for bounded channel consumption and unsafe detached work.

## Test scenarios
- Positive: “A request starts 100 tasks and shares one DbContext; fix cancellation and concurrency safely.”
- Negative: “Review a protobuf field-number change” routes to `api-contract-review` / `dotnet-code-review`.
- Boundary: a production hang asks both code-flow analysis here and dump/trace collection via `dotnet-diagnostics`.

## Related skills
`dotnet-diagnostics`, `messaging-patterns`, `efcore-patterns`, `testing-quality`, `logging-observability`.

Files in this skill

  • SKILL.md3.7 KB
  • examples.md1.3 KB

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.