Skip to content

Commit e74eacc

Browse files
committed
fix invalid status on longpoll window timeout
1 parent 035fde9 commit e74eacc

2 files changed

Lines changed: 46 additions & 1 deletion

File tree

lib/phoenix/transports/long_poll.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ defmodule Phoenix.Transports.LongPoll do
8888
body
8989
|> String.splitter(["\n", "\r\n"])
9090
# |> Stream.take(@max_poll_batch_size)
91-
|> Enum.find(fn part ->
91+
|> Enum.find_value(fn part ->
9292
msg =
9393
case part do
9494
"[" <> _ = txt -> {txt, :text}

test/phoenix/integration/long_poll_channels_test.exs

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,22 @@ defmodule Phoenix.Integration.LongPollChannelsTest do
115115
end
116116
end
117117

118+
defmodule SlowSocket do
119+
@behaviour Phoenix.Socket.Transport
120+
121+
def child_spec(_opts), do: :ignore
122+
def connect(_), do: {:ok, %{}}
123+
def init(state), do: {:ok, state}
124+
125+
def handle_in(_message, state) do
126+
Process.sleep(:infinity)
127+
{:ok, state}
128+
end
129+
130+
def handle_info(_message, state), do: {:ok, state}
131+
def terminate(_reason, _state), do: :ok
132+
end
133+
118134
defmodule Endpoint do
119135
use Phoenix.Endpoint, otp_app: :phoenix
120136

@@ -139,6 +155,13 @@ defmodule Phoenix.Integration.LongPollChannelsTest do
139155
check_origin: ["//example.com"],
140156
connect_info: [:trace_context_headers, :x_headers, :peer_data, :uri]
141157
]
158+
159+
socket "/ws/slow", SlowSocket,
160+
longpoll: [
161+
window_ms: 100,
162+
pubsub_timeout_ms: 200,
163+
check_origin: ["//example.com"]
164+
]
142165
end
143166

144167
setup %{adapter: adapter} do
@@ -597,6 +620,28 @@ defmodule Phoenix.Integration.LongPollChannelsTest do
597620
assert resp.body["status"] == 410
598621
end
599622
end
623+
624+
test "publish responds with 408 when transport_dispatch times out" do
625+
resp = poll(:get, "/ws/slow", "2.0.0", %{}, nil)
626+
assert resp.body["status"] == 410
627+
assert resp.status == 200
628+
629+
session = Map.take(resp.body, ["token"])
630+
631+
resp =
632+
poll(:post, "/ws/slow", "2.0.0", session, [
633+
%{
634+
"topic" => "room:lobby",
635+
"event" => "ping",
636+
"ref" => "1",
637+
"join_ref" => "1",
638+
"payload" => %{}
639+
}
640+
])
641+
642+
assert resp.status == 200
643+
assert resp.body["status"] == 408
644+
end
600645
end
601646

602647
for {serializer, vsn, join_ref} <- [

0 commit comments

Comments
 (0)