Skip to content

empty-catch: sdks/python/pmxt/ws_client.py:161 — except Exception: pass silently masks ws.close() failure during connect-retry cleanup #1896

Closed as duplicate

Description

@realfishsam

Violation

try:
    _connect_websocket(ws, url, timeout=10)
    last_error = None
    break
except Exception as exc:
    last_error = exc
    try:
        ws.close()
    except Exception:
        pass
    if attempt < max_attempts - 1:
        ...

Location

sdks/python/pmxt/ws_client.py:159-162, inside _ensure_connected

Why It Matters

When a connection attempt fails and the socket is being torn down before the next retry, any failure to close the half-open socket is discarded with no logging. This can hide resource leaks (unclosed sockets/file descriptors across retries) and makes it impossible to diagnose why a retry loop is behaving unexpectedly, since the only visible error becomes last_error from the connect failure, not the close failure.

Suggested Fix

Log the close failure at debug/warning level (consistent with how close() elsewhere in this file now handles cleanup errors, e.g. via logging.warning) instead of silently discarding it.


Found by automated code hygiene audit

Activity

  1. nightcityblade commented on Aug 17, 2026

    @nightcityblade

    Hi, I'd like to work on this. I'll submit a focused fix with a regression test shortly.

  2. realfishsam commented on Aug 18, 2026

    @realfishsam
    ContributorAuthor

    Closing as duplicate of #1106. Same underlying finding — the except Exception: pass wrapping ws.close() during connect-retry teardown in _ensure_connected in sdks/python/pmxt/ws_client.py (line numbers drifted from 132 to 159-162 due to unrelated config changes, but it's the same catch block). Note there's already an open PR (#1127) against #1106 for this fix — @nightcityblade you may want to check that first to avoid duplicate work.


    Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions