Binary pushes don't work over the LongPoll transport

Aperta
#6,906 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@mandar1045 ci sta già lavorando.

Dal 14/11/2026.

  • #6907 di @mandar1045 — aperta

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
elixir, javascript
Ambito
backend

Direzione di ricerca

Start with Phoenix.Transports.LongPoll.Server, where the {:push, ...} and {:reply, ...} clauses drop the frame opcode before buffering, and with the LongPoll client path in longpoll.js that parses the messages list. Run the LongPoll transport tests and add a case that pushes {:binary, <<255,1,2>>} then another message, checking the poll returns both without a 500 and the client parses them. Done means binary server-to-client frames round-trip over LongPoll as they do over WebSocket; note #6907 already proposes a base64 approach, so review it first.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Pushing binary data from a channel doesn't work when the client is on the LongPoll transport.

def handle_info(:send_bin, socket) do
  push(socket, "bin", {:binary, <<255, 1, 2>>})
  {:noreply, socket}
end

Over WebSocket this works fine. Over LongPoll:

  • if the data is not valid UTF-8, the poll request fails with a 500 ({:invalid_byte, 255} from the JSON encoder), and since the server already cleared its buffer, every other buffered message in that poll is lost too (including the join reply in my test)
  • if the data happens to be valid UTF-8, the raw binary frame ends up as a string in the messages list, e.g. "\u0000\u0001\u0006\u00031room:xbinhello", and phoenix.js fails trying to JSON.parse it

Looks like Phoenix.Transports.LongPoll.Server drops the opcode ({:push, {_, reply}, state} / {:reply, status, {_, reply}, state}) and buffers the binary as if it was text. Client to server binary over LongPoll is already handled (base64 encoded, from #5513), but the server to client direction isn't.

One option would be to base64 encode binary frames on the server like the upload path does, and have longpoll.js decode them before handing them to the socket.

Lingua principale
Elixir
Stelle
23.2k
Fork
3.2k
Merge medio
16h 35m
PR unite (30g)
18

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di phoenixframework/phoenix

Tutte le issue di phoenixframework/phoenix

Issue simili

Altre issue su Elixir

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.