Message-ID: From: "davecramer (@davecramer)" To: "pgjdbc/pgjdbc" Date: Wed, 20 May 2026 13:08:14 +0000 Subject: [pgjdbc/pgjdbc] PR #4080: Refactor pgstream to use threading List-Id: X-GitHub-Author-Id: 406518 X-GitHub-Author-Login: davecramer X-GitHub-Issue: 4080 X-GitHub-Repo: pgjdbc/pgjdbc X-GitHub-State: open X-GitHub-Type: pull_request X-GitHub-Url: https://github.com/pgjdbc/pgjdbc/pull/4080 Content-Type: text/plain; charset=utf-8 fix: make fastpath, copy, and notify protocols work with async message reader When asyncReading is enabled, the AsyncMessageReader thread owns the socket and feeds messages into a MessageQueue. Several protocol methods were still reading directly from pgStream, causing deadlocks: - receiveFastpathResult: used by Large Object operations - processCopyResults/initCopy: used by COPY protocol - processNotifies: used by async notification listening Convert all direct pgStream reads in these methods to use the queue-aware helpers (nextMessageType, readInt4, readBytes, etc). Add helper methods: - hasMessagePending(): checks queue or stream based on mode - peekNextMessageType(): non-blocking peek for copy protocol - readCopyDataLength(): handles length field differences between modes - readBytes(): reads raw bytes from payload or stream Make nextMessageType() use timed poll (1s) with connection-closed detection and socket timeout respect, preventing indefinite hangs when the connection is broken externally. Add processNotifies async mode path that uses timed queue polling instead of socket timeouts for notification wait behavior.