XX-net/XX-Net · info

ConnectionPipe remove sock e:%r

Error message

ConnectionPipe remove sock e:%r

What it means

ConnectionPipe.remove_sock logs this warning when cleaning up a socket fails unexpectedly — typically because the socket was already closed/removed, so the sock_conn_map lookup or select2.unregister throws. It is a benign race in teardown: close_sock and do_stop can both try to remove the same sock.

Source

Thrown at code/default/x_tunnel/local/base_container.py:474

                if not res:
                    # self.xlog.debug("remove_sock_event %s conn:%d event:%s removed all", sock, conn.conn_id, event)
                    del self.sock_conn_map[sock]
            except Exception as e:
                self.xlog.exception("remove_sock_event %s event:%s e:%r", sock, event, e)

    def remove_sock(self, sock):
        with self._lock:
            if sock not in self.sock_conn_map:
                return

            try:
                conn = self.sock_conn_map[sock]
                self._debug_log("remove_sock all events conn:%d", conn.conn_id)
                del self.sock_conn_map[sock]
                self.select2.unregister(sock)
            except Exception as e:
                # error will happen when sock closed
                self.xlog.warn("ConnectionPipe remove sock e:%r", e)

    def close_sock(self, sock, reason):
        if sock not in self.sock_conn_map:
            return

        try:
            conn = self.sock_conn_map[sock]
            # self.xlog.info("close conn:%d", conn.conn_id)
            self.remove_sock(sock)

            conn.transfer_peer_close(reason)
            conn.do_stop(reason=reason)
        except Exception as e:
            self.xlog.exception("close_sock %s e:%r", sock, e)

    def reset_all_connections(self):
        for sock, conn in dict(self.sock_conn_map).items():
            self.close_sock(sock, "reset_all")

View on GitHub (pinned to cfa5bc17b6)

Solutions

  1. No action usually needed — the socket is already removed/closed
  2. If the log is noisy, guard remove_sock with a `if sock not in self.sock_conn_map: return` check or catch KeyError silently
  3. Reduce double-closing by centralizing teardown through one path

Example fix

# before
conn = self.sock_conn_map[sock]

def remove_sock(self, sock):
    if sock not in self.sock_conn_map:
        return
    ...
Defensive patterns

Strategy: try-catch

Try / catch

try:
    pipe.remove_sock(sock)
except Exception:
    pass  # already cleaned up; benign teardown race

Prevention

When it happens

Trigger: A connection ends while both the read loop and shutdown path call close_sock/remove_sock for the same socket; second removal hits KeyError or an unregistered-fd error from select2.

Common situations: High connection churn (many simultaneous disconnects), server shutdown while connections are active — the warning is noise rather than a fault.

Related errors


AI-assisted analysis of XX-net/XX-Net@cfa5bc17b6 (2026-08-27). Data as JSON: /api/errors/6de6f255eb7eddb8. Report an issue: GitHub.