[BUG] Claude Code: Connection leak causing "offline" errors after 1-2 hours (WSL2)

Resolved 💬 3 comments Opened Jul 24, 2025 by WalkerHi11 Closed Jul 27, 2025

Description

Claude Code experiences a progressive connection leak that causes it to become unresponsive and show "offline" errors after running for 1-2 hours. The issue is resolved temporarily by running wsl --shutdown, but returns after another 1-2 hours of usage.

Environment

  • OS: Windows 11 with WSL2
  • WSL Distribution: Ubuntu
  • Node.js Version: v22.14.0
  • Claude Code Version: Latest
  • Installation method: npm/nvm

Steps to Reproduce

  1. Start Claude Code in WSL2 environment
  2. Use Claude Code normally for 1-2 hours
  3. Notice progressive slowdown and eventual "offline" errors
  4. Issue persists until wsl --shutdown is executed

Expected Behavior

Claude Code should maintain stable performance and connection handling over extended periods without requiring WSL restarts.

Actual Behavior

  • Claude Code progressively leaks TCP connections
  • After 1-2 hours, accumulates 100+ zombie sockets
  • Eventually shows "offline" errors and becomes unresponsive
  • Creates new HTTPS connections without closing existing ones

Diagnostic Information

Memory Status (not the issue)

$ free -h
               total        used        free      shared  buff/cache   available
Mem:            39Gi       3.9Gi        33Gi       169Mi       2.4Gi        35Gi
Swap:          4.0Gi          0B       4.0Gi

File Descriptor Count

$ lsof -p $(pgrep claude) | wc -l
10932

Network Statistics

$ ss -s
Total: 481
TCP:   297 (estab 62, closed 159, orphaned 58, timewait 0)

Connection Analysis

Claude Code (PID 1460) shows extensive connection leaks to 103.57.36.34.bc.googleusercontent.com:

  • 96+ ESTABLISHED HTTPS connections to the same host
  • 100+ zombie TCP sockets (showing as "protocol: TCP" with no details)
  • File descriptors ranging from fd=42 to fd=244+

Sample Connection Output

claude  1460 mtime   49u     IPv4             366595       0t0    TCP 172.24.181.33:49200->103.57.36.34.bc.googleusercontent.com:https (ESTABLISHED)
claude  1460 mtime   53u     sock                0,8       0t0 357987 protocol: TCP
claude  1460 mtime   59u     sock                0,8       0t0 357988 protocol: TCP
[... continues with 100+ similar entries ...]

Root Cause Analysis

The issue appears to be that Claude Code:

  1. Creates new HTTPS connections for each API request
  2. Does not properly close or reuse these connections
  3. Lacks proper connection pooling or keep-alive timeout handling
  4. Accumulates zombie sockets that are not properly garbage collected

Workaround

Currently using a monitoring script to restart Claude Code before it exhausts resources:

#!/bin/bash
while true; do
    FD_COUNT=$(lsof -p $(pgrep claude) 2>/dev/null | wc -l)
    if [ "$FD_COUNT" -gt 150 ]; then
        pkill claude && sleep 2 && claude &
    fi
    sleep 300
done

Additional Context

  • Issue is specific to long-running sessions
  • Performance degradation is gradual over 1-2 hours
  • All leaked connections are to Anthropic's API infrastructure (Google Cloud)
  • This significantly impacts developer experience for extended coding sessions

\

Let me know if you need any additional diagnostic information.

View original on GitHub ↗

This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗