You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
pgoutput: NullReferenceException with two-phase slots and stream aborts, misread stream aborts with protocol V4 unless streaming = parallel #6696
Several bugs in the pgoutput decoder (PgOutputAsyncEnumerable.cs unless noted):
A slot with two-phase decoding enabled (PostgreSQL 15+) sends prepared-transaction messages whatever proto_version the client requests (postgres logical.c:674). Npgsql allocates those message instances only for protocol V3 and later, so a V1 or V2 session fails with NullReferenceException at the first prepared transaction (:80-87, 450).
PostgreSQL 18.0 to at least 18.6 can send a Stream Abort even with streaming off and at any protocol version (postgres bug #19616, fixed on REL_18_STABLE in caa463e3f8d). With V1, Npgsql has no instance for it either: NullReferenceException (:89-96, 441, postgres caa463e3f8d). With V4, Npgsql reads it as the 24-byte variant of 3 and misreads what follows (:428-435).
With V4 and streaming = on, Npgsql reads every Stream Abort as the 24-byte parallel variant, but the server sends the abort LSN and timestamp only with streaming = parallel (:428-443, postgres pgoutput.c:1901, proto.c:1157-1177). The 16 extra bytes come from what follows, which is then misread (inferred).
Transaction GIDs are read with synchronous I/O when they aren't fully buffered (:455 and the four similar reads).
Unknown message codes and unknown tuple types in Update and Delete messages throw NotSupportedException, and unknown column kinds ArgumentOutOfRangeException (TupleEnumerator.cs:69), without breaking the connection (:321-322, 363-364, 507-509). In an Insert, an unknown tuple type is read as a new row, since only a Debug.Assert checks it (:261). The connection stays in the middle of the stream, in the Replication state, because the wrapper never disposes the inner enumerator (LogicalReplicationConnectionExtensions.cs:177-179): later commands throw NpgsqlOperationInProgressException, and the walsender keeps the slot.
Reading a ReplicationValue after it was consumed (e.g. after the column enumeration moved past it) reads whatever comes next on the wire instead of throwing (ReplicationValue.cs:114-126, 128-130). Get<int?>() on a NULL fails in text mode (inferred: the conversion is resolved before the NULL check, ReplicationValue.cs:154, 157).
1 and 2 are regressions in 9.0, where the per-version allocation came with protocol V4 support (ea3b161, #5761); 8.0 allocates every instance. 3 exists since V4 support (git log -S). 4, 5, 7 and 8 affect 8.0 too.
Activity