#!/usr/bin/env python3 # stall.py: a client that gets its backend stuck in ClientWrite and stays alive. # Used by repro-standby.sh (rows 1-5 and 9 of coverage-matrix.txt). # usage: python3 stall.py PORT DBNAME "SQL" (TCP to 127.0.0.1, trust auth) # It sends one simple Query, never reads the result, and prints "SENT ". import os, socket, struct, sys, time port, dbname, sql = int(sys.argv[1]), sys.argv[2], sys.argv[3] user = os.environ.get("PGUSER") or os.environ.get("USER", "postgres") s = socket.create_connection(("127.0.0.1", port)) def recv_exact(n): buf = b"" while len(buf) < n: c = s.recv(n - len(buf)) if not c: sys.exit("server closed the connection") buf += c return buf params = b"user\0" + user.encode() + b"\0database\0" + dbname.encode() + b"\0\0" s.sendall(struct.pack("!II", 8 + len(params), 196608) + params) pid = 0 while True: t = recv_exact(1) (ln,) = struct.unpack("!I", recv_exact(4)) body = recv_exact(ln - 4) if t == b"R" and struct.unpack("!I", body[:4])[0] != 0: sys.exit("only trust authentication is supported") if t == b"K": pid = struct.unpack("!I", body[:4])[0] if t == b"E": sys.exit("error during startup: %r" % body) if t == b"Z": break q = sql.encode() + b"\0" s.sendall(b"Q" + struct.pack("!I", 4 + len(q)) + q) print("SENT", pid, s.getsockname()[1], flush=True) while True: time.sleep(3600)