Error during WebSocket handshake: Unexpected response code: 500
in my browser.
The Phoenix code is
defmodule SyntaxWeb.UserSocket do
use Phoenix.Socket
def connect(%{"token" => token}, socket, _connect_info) do
IO.inspect "get here"
case Phoenix.Token.verify(socket, "user socket", token, max_age: 1209600) do
{:ok, user_id} ->
IO.inspect "and get there"
{:ok, assign(socket, :current_user, Syntax.Accounts.get_user!(user_id))}
{:error, reason} ->
IO.inspect "bad user socket token : #{reason}"
:error
end
end
end
The javascript code uses is :
let { Socket } = require('phoenix-channels');
socket = new Socket("ws:" + myurl + "/socket", {params: {token: userToken}})
socket.connect();
The request for connection reaches the server as I have both āget hereā and āget thereā displayed. Would anyone have an idea of what goes wrong ?
Unfortunately there is nothing display on the server side : like everything is going fine.
I found out that the version of my code works with Phoenix version 1.4.0. The version Iām having problem with is 1.4.9. Iām thinking that maybe there is a compatibility issue with phoenix-channels, or maybe the rest of my code is not compatible with version 1.4.9. On my EndPoint I have
I now have the exact same version of erlang/elixir/phoenix on dev and production, but I keep having the same issue on production while everything is fine on dev.
The only thing I can think of is the following: I use the following trick on production so that Cowboy can accept connections on the port 80 :
I changed nothing, and at some point it started to work. This is mysteriousā¦
Maybe some cache system somewhere caused this.
Addition :
I found something more specific : The problem disappear when I suppress the website cookie from my browser. I have to find out what causes this.
Is it a particularly large cookie? A marketing installation caused this issue in my app once due to a shared domain. The solution in that case was to allow larger cookies to be processed by cowboy.