Binary pushes don't work over the LongPoll transport

Đang mở
#6,906 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

@mandar1045 đang làm issue này rồi.

Từ ngày 14/11/2026.

  • #6907 của @mandar1045 — đang mở

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
35/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
elixir, javascript
Lĩnh vực
backend

Hướng nghiên cứu

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.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Elixir
Star
23.2k
Fork
3.2k
Merge trung bình
16 giờ 35 phút
Pull request đã merge (30 ngày)
18

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của phoenixframework/phoenix

Tất cả issue của phoenixframework/phoenix

Issue tương tự

Thêm issue về Elixir

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.