Skip to content

Replication client uses wrong Postgres-epoch constant (946080000000, 7 days short) #4002

@yashs33244

Description

@yashs33244

Summary

internal-packages/replication/src/client.ts uses 946080000000 as the Postgres→Unix epoch offset (ms) in two places — keepalive decode (~L366) and the standby status ack encode (const now = Date.now() - 946080000000;, ~L661). new Date(946080000000) is 1999-12-25T00:00:00Z; the correct Postgres epoch is 2000-01-01T00:00:00Z = 946684800000. The difference is exactly 7 days (604800000 ms).

The sibling parser pgoutput.ts has it right, with the comment (POSTGRES_EPOCH_JDATE - UNIX_EPOCH_JDATE) * USECS_PER_DAY == 946684800000000 (micros) → 946684800000 ms.

Impact

Low / observability. The decoded keepalive timestamp is currently unused by the consumer, and the encoded standby-reply timestamp only surfaces as pg_stat_replication.reply_time (WAL feedback is driven by the LSN bytes, not this timestamp). So it's a wall-clock/observability defect, not a replication-correctness break — but it's wrong by 7 days in two spots.

Suggested fix

Replace both 946080000000 literals with 946684800000 (ideally a shared named constant POSTGRES_EPOCH_MS), mirroring pgoutput.ts.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions