Longpool not working in Phoenix

I can not figure out how to make phoenix sockets longpool work. My config is like this:
in endpoint.ex:

socket("/socket", Carts.ApiWeb.CartSocket, websocket: true, longpoll: true)

in cart_socket.ex:

channel("cart:*", Carts.ApiWeb.CartChannel)

in config:

config :carts_api, Carts.ApiWeb.Endpoint,
  http: [port: "${CARTS_PORT}", protocol_options: [max_keepalive: 200]],
  url: [host: "${CARTS_URL}", port: 443, scheme: "https"],
  secret_key_base: "${SECRET_KEY_BASE}",
  check_origin: false

And I keep being bombarded with this error on server side side:

Elixir.ErlangError · Erlang error: {{%Phoenix.Router.NoRouteError{conn: %Plug.Conn{adapter: {Plug.Cowboy.Conn, :…}, assigns: %{}, before_send: [#Function<0.44602488/1 in Carts.ApiWeb.PipelineInstrumenter.call/2>, #Function<1.112466771/1 in Plug.Logger.call/2>], body_params: %{}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: “.zuppler.com", method: “GET”, owner: #PID<0.6594.29>, params: %{“vsn” => “2.0.0”}, path_info: [“socket”, “longpoll”], path_params: %{}, port: 80, private: %{Carts.ApiWeb.Router => {[], %{Zuppler.Phoenix.Utils.PingPongPlugRouter => [“ping”]}}, :phoenix_endpoint => Carts.ApiWeb.Endpoint, :phoenix_router => Carts.ApiWeb.Router, :plug_session_fetch => #Function<1.64872641/1 in Plug.Session.fetch_session/1>}, query_params: %{“vsn” => “2.0.0”}, query_string: “vsn=2.0.0&”, remote_ip: {192, 168, 126, 248}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, req_headers: [{“accept”, "/"}, {“accept-encoding”, “gzip, deflate, peerdist”}, {“accept-language”, “en-US”}, {“cache-control”, “no-cache”}, {“content-type”, “application/json”}, {“dnt”, “1”}, {“host”, ".zuppler.com"}, {“origin”, “https://www.cuginisyracuse.com”}, {“referer”, “https://www.cuginisyracuse.com/”}, {“ua-cpu”, “AMD64”}, {“user-agent”, “Mozilla/5.0 (Windows NT 6.1; Win64; x64; Trident/7.0; rv:11.0) like Gecko”}, {“x-forwarded-for”, “65.196.116.115”}, {“x-forwarded-host”, ".zuppler.com"}, {“x-forwarded-port”, “443”}, {“x-forwarded-proto”, “https”}, {“x-original-uri”, “/socket/longpoll?vsn=2.0.0&”}, {“x-p2p-peerdist”, “Version=1.0”}, {“x-real-ip”, “65.196.116.115”}, {“x-request-id”, “2c83b337fe13a6b236963044ebe5a213”}, {“x-scheme”, “https”}], request_path: “/socket/longpoll”, resp_body: nil, resp_cookies: %{}, resp_headers: [{“cache-control”, “max-age=0, private, must-revalidate”}, {“x-request-id”, “2c83b337fe13a6b236963044ebe5a213”}, {“vary”, “Origin”}, {“access-control-allow-origin”, “https://www.cuginisyracuse.com”}, {“access-control-expose-headers”, “”}, {“access-control-allow-credentials”, “true”}], scheme: :http, script_name: [], secret_key_base: :…, state: :unset, status: nil}, message: “no route found for GET /socket/longpoll (Carts.ApiWeb.Router)”, plug_status: 404, router: Carts.ApiWeb.Router}, [{Carts.ApiWeb.Router, :“call (overridable 2)”, 2, [file: ‘lib/phoenix/router.ex’, line: 324]}, {Carts.ApiWeb.Router, :call, 2, [file: ‘lib/plug/error_handler.ex’, line: 64]}, {Carts.ApiWeb.Endpoint, :plug_builder_call, 2, [file: ‘lib/carts-api-web/endpoint.ex’, line: 1]}, {Carts.ApiWeb.Endpoint, :call, 2, [file: ‘lib/carts-api-web/endpoint.ex’, line: 1]}, {Plug.Cowboy.Handler, :init, 2, [file: ‘lib/plug/cowboy/handler.ex’, line: 12]}, {:cowboy_handler, :execute, 2, [file: ‘/tmp/build/deps/cowboy/src/cowboy_handler.erl’, line: 41]}, {:cowboy_stream_h, :execute, 3, [file: ‘/tmp/build/deps/cowboy/src/cowboy_stream_h.erl’, line: 296]}, {:cowboy_stream_h, :request_process, 3, [file: ‘/tmp/build/deps/cowboy/src/cowboy_stream_h.erl’, line: 274]}]}, {MasterProxy.Plug, :call, [%Plug.Conn{adapter: {Plug.Cowboy.Conn, :…}, assigns: %{}, before_send: [], body_params: %Plug.Conn.Unfetched{aspect: :body_params}, cookies: %Plug.Conn.Unfetched{aspect: :cookies}, halted: false, host: ".zuppler.com", method: “GET”, owner: #PID<0.6594.29>, params: %Plug.Conn.Unfetched{aspect: :params}, path_info: [“socket”, “longpoll”], path_params: %{}, port: 80, private: %{}, query_params: %Plug.Conn.Unfetched{aspect: :query_params}, query_string: “vsn=2.0.0&”, remote_ip: {192, 168, 126, 248}, req_cookies: %Plug.Conn.Unfetched{aspect: :cookies}, req_headers: [{“accept”, "/”}, {“accept-encoding”, “gzip, deflate, peerdist”}, {“accept-language”, “en-US”}, {“cache-control”, “no-cache”}, {“content-type”, “application/json”}, {“dnt”, “1”}, {“host”, “*.zuppler.com"}, {“origin”, “https://www.cuginisyracuse.com”}, {“referer”, “https://www.cuginisyracuse.com/”}, {“ua-cpu”, “AMD64”}, {“user-agent”, “Mozilla/5.0 (Windows NT 6.1; Win64; x64; Trident/7.0; rv:11.0) like Gecko”}, {“x-forwarded-for”, “65.196.116.115”}, {“x-forwarded-host”, ".zuppler.com”}, {“x-forwarded-port”, “443”}, {“x-forwarded-proto”, “https”}, {“x-original-uri”, “/socket/longpoll?vsn=2.0.0&”}, {“x-p2p-peerdist”, “Version=1.0”}, {“x-real-ip”, “65.196.116.115”}, {“x-request-id”, “2c83b337fe13a6b236963044ebe5a213”}, {“x-scheme”, “https”}], request_path: “/socket/longpoll”, resp_body: nil, resp_cookies: %{}, resp_headers: [{“cache-control”, “max-age=0, private, must-revalidate”}], scheme: :http, script_name: [], secret_key_base: nil, state: :unset, status: nil}, []]}}

I have no idea how to fix this :frowning_face:

Check out this recent issue on Phoenix’s github: https://github.com/phoenixframework/phoenix/issues/2914#issuecomment-398111457

Chris’s code example may provide some useful hints.

And perhaps you should post your javascript as well.

1 Like

I will try to extract the js code from the SPA application, I have not written that.
But looking inside this crash it shows that the client tries to connect to longpool url: “/socket/longpoll?vsn=2.0.0&”
This is why I presume it may be a server side issue.
Should this route be automatically added by Phoenix or there is something I need to do?