go-context-deadline-patterns

Implement context-aware I/O methods with deadlines and cancellation handling.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/PremModhaOfficial/sdk-pipeline --skill go-context-deadline-patterns
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: go-context-deadline-patterns
Source: https://github.com/PremModhaOfficial/sdk-pipeline/tree/main/skills/go-context-deadline-patterns
Command: npx skills add https://github.com/PremModhaOfficial/sdk-pipeline --skill go-context-deadline-patterns

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes scripts (resource) and references (resource) components.

What problem does it solve?

This Skill guides developers in implementing context-aware I/O methods that respect cancellation signals and deadlines, preventing resource leaks and ensuring safe concurrency.

Core Features & Use Cases

  • Deadline Propagation: Implements patterns to respect existing deadlines and apply default timeouts when none are set, ensuring predictable operation timing.
  • Cancellation Safety: Ensures resources are released with defer cancel() and uses select statements to handle ctx.Done(), avoiding goroutine leaks.
  • Use Case: When designing a network client or cleanup operation, apply these patterns to guarantee timely aborts under cancellation or timeout conditions.

Quick Start

Follow the pattern to probe ctx.Deadline(), derive timeouts with context.WithTimeout, and incorporate select statements to handle cancellations during delays or retries.

Frequently Asked Questions about go-context-deadline-patterns

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I handle context cancellation and timeouts in Go?

Handle context cancellation and timeouts in Go by using select statements to listen for ctx.Done() and applying context.WithTimeout. This ensures operations abort predictably and resources are released safely.

Why does my Go application leak goroutines during network I/O?

Go applications leak goroutines during network I/O when operations block without checking ctx.Done(). Using select statements to handle cancellation signals and deferring cancel() prevents these leaks.

How do I propagate deadlines in Go network clients?

Propagate deadlines in Go network clients by probing ctx.Deadline() and deriving timeouts with context.WithTimeout. This ensures child operations respect parent time limits and abort safely.

What is the best way to apply default timeouts in Go when no deadline is set?

The best way to apply default timeouts in Go is to check ctx.Deadline() and, if none exists, wrap the context using context.WithTimeout. This guarantees predictable execution timing for I/O methods.

When do I need context-aware I/O methods in Go concurrency?

You need context-aware I/O methods in Go concurrency when designing network clients or cleanup operations that require timely aborts. Handling cancellation signals prevents resource leaks and ensures safe concurrent execution.