websocket

Manage WebSocket connection lifecycles with AbortSignal cleanup on timeout, error, or cancel.

Updated Feb 21, 2026
One-click install
npx skills add https://github.com/aquarius-wing/polymarket-dev-tools --skill websocket-aquarius-wing
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: websocket
Source: https://github.com/aquarius-wing/polymarket-dev-tools/tree/main/.cursor/skills/websocket
Command: npx skills add https://github.com/aquarius-wing/polymarket-dev-tools --skill websocket-aquarius-wing

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

WebSocket connections can remain open after they are no longer needed, causing resource leaks, duplicated listeners, and hung promises. This Skill explains when to close sockets and how to support external cancellation so long-lived subscriptions reliably terminate on success, timeout, error, or caller abort.

Core Features & Use Cases

  • Explicit lifecycle rules: When to immediately close a socket (success, timeout, error, external cancel) to avoid leaks.
  • AbortSignal integration: Accept and respond to AbortSignal to allow callers (for example React components) to cancel listeners on unmount.
  • Unified cleanup: Clear timers, remove listeners, and close sockets idempotently to prevent double resolve/reject and race conditions.
  • Use case: Implement a real-time transaction subscription that resolves when a target event arrives, rejects on error, times out after N milliseconds, and cancels when the user navigates away.

Quick Start

Use the websocket skill to wrap a WebSocket subscription with an AbortSignal so it closes cleanly on success, timeout, error, or external abort.

Frequently Asked Questions about websocket

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

FAQPage Schema
How do I prevent WebSocket connection leaks in JavaScript applications?

Preventing WebSocket connection leaks requires explicitly closing sockets on success, timeout, or error, and clearing all associated timers and listeners. This ensures idempotent termination and avoids leaving connections open after they are no longer needed.

How do I cancel a real-time WebSocket subscription when a React component unmounts?

Cancel a real-time WebSocket subscription on React component unmount by integrating an AbortSignal. The socket listener responds to the external cancellation signal, triggering unified cleanup to close the connection safely and prevent resource leaks.

What is the best way to handle WebSocket timeouts and errors without hanging promises?

Handle WebSocket timeouts and errors without hanging promises by implementing explicit lifecycle rules. Applying unified cleanup to close sockets and clear timers on timeout or error prevents double resolve or reject and eliminates race conditions.

Why does my WebSocket listener duplicate events after a connection error?

Your WebSocket listener duplicates events after a connection error because previous sockets were not closed properly. Implementing idempotent cleanup to remove listeners and close sockets on errors prevents duplicated listeners and lingering connections.

Does this WebSocket lifecycle management approach work for long-lived subscriptions?

Yes, this WebSocket lifecycle management approach is specifically designed for long-lived subscriptions and real-time listeners. It supports external cancellation via AbortSignal and enforces explicit closure on success, timeout, error, or caller abort to ensure reliable termination.