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

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

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