Skip to content

Broadcast replay misses messages when the database timezone isn't UTC #2364

Description

@mandar1045

TL;DR:
realtime.send() doesn't set inserted_at, so it falls back to now() cast to a timestamp, which is the session's local time. Replay compares it against UTC, so if the database (or session) isn't UTC, replay returns the wrong messages or nothing at all.

With the timezone set to Asia/Kolkata, a message sent now is stored 5.5h in the future and replay returns nothing, even with since: 0.

alter database postgres set timezone to 'Asia/Kolkata';
-- new session
select realtime.send('{"a":1}', 'ev', 'room', true);
select inserted_at, now() at time zone 'utc' from realtime.messages;
-- inserted_at is 5.5h ahead

Everything else already treats inserted_at as UTC (replay, partitions, realtime.authorize), and the same mismatch was fixed for commit_timestamp in #527. #2202 switches the default to clock_timestamp(), but that's still local time.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions