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!

First 3 of 3 Posts Switch mode

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
jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
roeland
Kia ora, We have been using elixir-google-api to connect to Google Drive. However, with the updates to Tesla due to CVEs this is now bro...
New
rahultumpala
Hello, I have an Elixir backend that implements a custom protocol over TCP. I want to load test the backend and assess the performance o...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
juhalehtonen
There has been a thread to discuss the Stack Overflow Developer Survey on this forum every year since 2018, so here’s yet another one for...
New

We're in Beta

About us Mission Statement