katehedgpeth

katehedgpeth

I am trying upgrade to Elixir 1.8, Erlang 21, and Phoenix 1.4. I’m getting an error with our custom http dispatch config, which was added when we were at Phoenix 1.3/Elixir 1.5.

Here is our config:

  config :site, SiteWeb.Endpoint,
    http: [
      dispatch: [
        {:_,
         [
           {"/socket/websocket", Phoenix.Endpoint.CowboyWebSocket,
            {Phoenix.Transports.WebSocket, {SiteWeb.Endpoint, SiteWeb.UserSocket, :websocket}}},
           {"/socket/longpoll", Plug.Cowboy.Handler,
            {Phoenix.Transports.LongPoll, {SiteWeb.Endpoint, SiteWeb.UserSocket, :longpoll}}},
           {:_, Plug.Cowboy.Handler, {SiteWeb.Endpoint, []}}
         ]}
      ]
    ]

And the error we’re seeing:

** (UndefinedFunctionError) function Phoenix.Endpoint.CowboyWebSocket.init/2 is undefined or private
    (phoenix) Phoenix.Endpoint.CowboyWebSocket.init(%{bindings: %{}, body_length: 0, cert: :undefined, has_body: false, headers: %{"accept-encoding" => "gzip, deflate, br", "accept-language" => "en-US,en;q=0.9", "cache-control" => "no-cache", "connection" => "upgrade", "cookie" => "_ga=GA1.2.323690242.1505750053; __insp_uid=4076678333; _ga=GA1.3.1382101712.1505318427; fs_uid=fullstory.com`AQKVD`5182813288529920:5629499534213120; __insp_wid=101978311; __insp_nv=false; __insp_targlpu=aHR0cHM6Ly9kZXYubWJ0YWNlLmNvbS8%3D; __insp_targlpt=TUJUQSAtIE1hc3NhY2h1c2V0dHMgQmF5IFRyYW5zcG9ydGF0aW9uIEF1dGhvcml0eQ%3D%3D; __insp_norec_sess=true; __insp_slim=1525973426869; mbta_id=32820746; _ga=GA1.4.323690242.1505750053; _site_key=SFMyNTY.g3QAAAAA.xxxBgGh7d8xGoy6cezO2La-1xvwRbt_RjIPutJlQj8U; _gid=GA1.3.930802726.1551714745; _gid=GA1.2.930802726.1551714745; mbta_visited_routes=CR-Fitchburg|85; _gid=GA1.4.930802726.1551714745; _gat_UA-82280837-1=1", "host" => "green.dev.mbtace.com", "origin" => "https://green.dev.mbtace.com", "pragma" => "no-cache", "sec-websocket-extensions" => "permessage-deflate; client_max_window_bits", "sec-websocket-key" => "IdIkX8mVrmEKVbPIdL0ZZw==", "sec-websocket-version" => "13", "upgrade" => "websocket", "user-agent" => "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_6) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.119 Safari/537.36", "x-amzn-trace-id" => "Root=1-5c7eece1-4c47339fb70d03ccbdd1d686", "x-forwarded-for" => "67.208.190.2, 67.208.190.2", "x-forwarded-port" => "443", "x-forwarded-proto" => "https", "x-real-ip" => "67.208.190.2"}, host: "green.dev.mbtace.com", host_info: :undefined, method: "GET", path: "/socket/websocket", path_info: :undefined, peer: {{172, 17, 0, 1}, 54138}, pid: #PID<0.6326.0>, port: 80, qs: "vsn=2.0.0", ref: SiteWeb.Endpoint.HTTP, scheme: "http", sock: {{172, 17, 0, 2}, 4000}, streamid: 9, version: :"HTTP/1.1"}, {Phoenix.Transports.WebSocket, {SiteWeb.Endpoint, SiteWeb.UserSocket, :websocket}})
    (cowboy) /root/deps/cowboy/src/cowboy_handler.erl:41: :cowboy_handler.execute/2
    (cowboy) /root/deps/cowboy/src/cowboy_stream_h.erl:296: :cowboy_stream_h.execute/3
    (cowboy) /root/deps/cowboy/src/cowboy_stream_h.erl:274: :cowboy_stream_h.request_process/3
    (stdlib) proc_lib.erl:249: :proc_lib.init_p_do_apply/3
Initial Call: :cowboy_stream_h.request_process/3
Ancestors: [#PID<0.6326.0>, #PID<0.2391.0>, #PID<0.2390.0>, SiteWeb.Endpoint, Site.Supervisor, #PID<0.2377.0>]

As far as I can tell, Phoenix.Endpoint.CowboyWebSocket hasn’t changed in a while, so I’m guessing that there was some change to how the args are being passed to that init function? I’m struggling to follow the pipeline to even figure out how this is getting called. If anyone has any suggestions they would be greatly appreciated!

Showing Posts 1 to 3

blatyo

blatyo

Conduit Core Team

I think you’re just using an old adapter. Phoenix.Endpoint.CowboyWebSocket appears to be for cowboy 1. If you upgraded to cowboy 2, I think you want to follow this: Phoenix.Endpoint.Cowboy2Adapter — Phoenix v1.8.8

blatyo

blatyo

Conduit Core Team

Out of curiosity, why are you using this feature? It appears you’re just passing what phoenix would pass for you by default. If you’re not doing anything custom, you can probably just delete that config.

katehedgpeth

katehedgpeth OP

After combing through the commits in the socket transport refactor in Phoenix 1.4 much more carefully, I believe I have solved my problem – I thought i would document it here in case anyone else comes across this same issue.

With the new socket transport, sockets do not appear to need their own dispatch transports; Phoenix.Endpoint.Cowboy2Handlers takes care of everything. So I was able to replace the above config with simply:

http: [
  dispatch: [
    {:_, [
      {:_, Phoenix.Endpoint.Cowboy2Handler, {SiteWeb.Endpoint, []}}
      ]}
  ]
]
— All posts loaded —

Where Next? Top

Trending in Questions Top

stjefim
Hello! Suppose you are building workflow (order / task / payment) processing system with the following requirements: Each workflow con...
New
itzmidinesh
Hi all, I’m working on a Phoenix project where I need to make external HTTP requests and I’m trying to choose between Req and HTTPoison....
New
pragdave
How do I tell Hologram not to escape HTML when substituting into templates? {Textile.render(@product.long_description)} escapes the HTM...
New
leoschweizer
Hi, we run different LLM models across a cluster, with each node loading a configurable subset. Model-specific queues let nodes consume ...
New
rlipscombe
I’d like to create a file with 600 permissions (rw-------), but there’s a race condition if I create it and then change the permissions. ...
New
saleyn
Is there a way to import record definitions in the iex shell for pretty printing (similar to the rr command in the erl shell)? This woul...
New
rlipscombe
When I use Mix.install with a git dependency, using git@github.com:... how do I change the SSH identity used? I’ve got two Github accoun...
New

Other Trending Topics Top

dominicletz
Hey there, I haven’t seen a list of useful Elixir specific skills for the popular AI tools yet so I’m starting one here with my first. ...
New
raa-ziq
Hi everyone :waving_hand: I wanted to share something I’ve been building — NowBlind, a random chat app designed to help people discover ...
New
mudasobwa
I fully migrated to my own harness from Anthropic/Gemini and I think it’s time to share it. Welcome DSH, the DeepSeek Harness, fully writ...
New
KristerV
Hey. Is there anyone here who creates agents in their apps? Not talking about using agents, but creating them. I’m finding it pretty diff...
New
OndrejValenta
(I just needed to vent somewhere and LinkedIn is full of hope, or hype, I’m not sure which exactly) AI dream has many faces, but general...
New
kip
Localize is the next generation localisation library for Elixir. Think of it as ex_cldr version 3.0. The first version will be released ...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews