Repository navigation
Conversation
A join with "private": null joins a public channel, but its client broadcasts are dropped. Null broadcast, presence and postgres_changes_options values should also act as if they were not sent.
Ecto casts null to nil without calling FlexibleBoolean, so "private": null
assigned private?: nil. Neither handle_in("broadcast", ...) clause matches nil,
so the channel joined as public and dropped every broadcast the client sent.
A null postgres_changes_options.timeout also became the server maximum
instead of the 15 second default.
Add Join.empty_values/0 and pass it to every join payload cast, so a null
option keeps its default like an omitted one.
mangeshraut712
left a comment
There was a problem hiding this comment.
Clear root-cause write-up. nil skipping the custom type's cast/1 and then matching neither handle_in("broadcast", …) clause is exactly the kind of silent failure that's hard to spot from the client side. The end-to-end channel test with ack: true is the right regression. Two defence-in-depth suggestions.
| `"private": null` would override the `false` default with `nil`. | ||
| """ | ||
| @spec empty_values() :: list() | ||
| def empty_values, do: [nil | Ecto.Changeset.empty_values()] |
There was a problem hiding this comment.
This fixes the parse side for the four payload modules. The accessors just above still pass the raw field through, though: private?/1 (do: private), ack_broadcast?/1, self_broadcast?/1, presence_enabled?/1. So any future path that leaves one of these nil would bring back the same silent drop. Examples: a new embed that forgets empty_values, or a %Join{} built or patched in code rather than via validate/1. Making the accessors return strict booleans (do: private == true, etc.) would make handle_in's private?: true / private?: false clauses exhaustive by construction. It costs nothing on the happy path.
Related, optional: when a "broadcast" push does reach the catch-all handle_in/3 (L605), the client gets no reply even with ack: true, and the log is at info. Replying {:reply, {:error, %{reason: "..."}}, socket} for that specific event would have made this bug visible to the sender immediately, without flooding Logflare.
Why
A client that joins with
"config": {"private": null}joins a public channel, but every broadcast it sends is dropped. The join succeeds and nothing is logged above info level, so the sender sees no error. Withack: truethe push never gets a reply. A garbage value like"private": "yes"falls back tofalse, sonullwas the only value that broke the channel.What changed
nulltonilwithout callingFlexibleBoolean, soJoin.private?/1returnednil. Neitherhandle_in("broadcast", ...)clause matchesprivate?: nil(one needstrue, the otherfalse), so broadcasts fell through to the catch-allhandle_in/3and were dropped.Join.empty_values/0([nil | Ecto.Changeset.empty_values()]). Every join payloadcast/4(Config,Broadcast,Presence,PostgresChangesOptions) now passes it, so anulloption keeps its default just like an omitted one.postgres_changes_options.timeout: null. Withwait: trueit was clamped to the server maximum (min(nil, max)) instead of the 15 second default.Scope
Join payload parsing only (
lib/realtime_web/channels/payloads/). Values other thannullcast exactly as before, including"", which was already an empty value.Blast Radius
Only joins that send
nullforprivate,broadcast.ack/self/replication_ready,presence.enabled/keyorpostgres_changes_options.wait/timeoutchange. Those options now read as their documented defaults. Apart fromprivateandtimeout, the server already treatednillikefalse, so their behaviour does not change.Verification
mix test test/realtime_web/channels/payloads/join_test.exs:63 test/realtime_web/channels/realtime_channel_test.exs:424on the test-only commit: 2 failures. The config came back withprivate: nil,ack: niland so on, and no broadcast reply arrived within 100ms. After the fix: 2 passed.mix test test/realtime_web/channels/payloads test/realtime_web/channels/realtime_channel_test.exs test/realtime_web/channels/realtime_channel: 458 passed.mix format --check-formatted: passes.mix compile --warnings-as-errors: fails only on existing Elixir 1.20 type warnings in untouched files (api.ex,application.ex,migrations.ex,forum/muster/scope.ex). The repo pins Elixir 1.19.5, so this was not checked on the pinned version.