Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cryptic error when http or https settings are provided without the port #5389

Closed
sasa1977 opened this issue Mar 30, 2023 · 2 comments
Closed
Assignees

Comments

@sasa1977
Copy link
Contributor

Environment

  • Elixir version (elixir -v): 1.14
  • Phoenix version (mix deps): 1.7.2
  • Operating system: Linux

Expected behavior

When http (or https) config is provided but doesn't include the port, the emitted error should be clear.

Actual behavior

The emitted error is very cryptic, and doesn't provide a useful clue for fixing it:

** (EXIT from #PID<0.95.0>) shutdown: failed to start child: SamplePhoenix.Endpoint
    ** (EXIT) an exception was raised:
        ** (RuntimeError) could not find persistent term for endpoint SamplePhoenix.Endpoint. Make sure your endpoint is started and note you cannot access endpoint functions at compile-time
            lib/phoenix/endpoint.ex:536: SamplePhoenix.Endpoint.persistent!/0
            lib/phoenix/endpoint.ex:544: SamplePhoenix.Endpoint.url/0
            (phoenix 1.7.2) lib/phoenix/endpoint/supervisor.ex:425: Phoenix.Endpoint.Supervisor.log_access_url/2
            (phoenix 1.7.2) lib/phoenix/endpoint/supervisor.ex:17: Phoenix.Endpoint.Supervisor.start_link/3

The minimal script to reproduce the bug:

# modified version of https://github.com/wojtekmach/mix_install_examples

Application.put_env(:phoenix, :json_library, Jason)

Application.put_env(:sample, SamplePhoenix.Endpoint,
  http: [ip: {127, 0, 0, 1}],
  server: true,
  secret_key_base: String.duplicate("a", 64)
)

Mix.install([
  {:plug_cowboy, "~> 2.5"},
  {:jason, "~> 1.0"},
  {:phoenix, "~> 1.7.0"}
])

defmodule SamplePhoenix.Endpoint do
  use Phoenix.Endpoint, otp_app: :sample
end

Supervisor.start_link([SamplePhoenix.Endpoint], strategy: :one_for_one)

To fix the error, we must add the port to the http settings, which is completely not obvious from the given error.

I've just had two issues reported in the site_encrypt library related to this bug. Here's one: sasa1977/site_encrypt#48. I could detect this situation in the library code and raise the error before forwarding to Phoenix, but I think it would be better if a more informative error is reported directly in Phoenix.

@williamweckl
Copy link

williamweckl commented Mar 30, 2023

I've experienced the same issue, was only able to solve because of your issue. Thank you @sasa1977 ❤️ !

In my case I'm using main_proxy and it is not obvious at all that you have to set a port to the endpoint that will not even be provided by a port.

Another thing to mention is that the ip is also necessary, tried with just the port configuration and it didn't work.

@gf3
Copy link

gf3 commented Apr 21, 2023

I've experienced the same issue, was only able to solve because of your issue. Thank you @sasa1977 ❤️ !

In my case I'm using main_proxy and it is not obvious at all that you have to set a port to the endpoint that will not even be provided by a port.

Another thing to mention is that the ip is also necessary, tried with just the port configuration and it didn't work.

hi @williamweckl we're also using main_proxy and running into the same issue—how did you end up solving it? we don't even have http or https configs for our non-proxy apps

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants