Phoenix dev mode Google Cloud Run

Is this possible to deploy a Phoenix application to Google Cloud Run with MIX_ENV=dev ? For some reasons when I try deploy in dev mode, it just crash when the application starts.

Since Cloud Run is using gVisor, could this be possible that Phoenix is making some system calls that gVisor would consider as dangerous and just kill the process?

1 Like

We are running MIX_ENV=prod without any problems, not sure why mix_ENV=dev wouldn’t work. Maybe phoenix_live_reload causes this because it tries to access the filesystem (and requires inotify)? You should be able to find more information in the logs on Google Cloud.

After some digging :

"textPayload": "Uncaught signal: 10, pid=43, tid=43, fault_addr=0."

Based on this post, signal 10 is for sys_mprotect. So it seems that yes, Phoenix is making some calls in dev mode that trigger some security rules. If anyone has a workaround or more information about this, it would be really cool ! :slight_smile:

Which “execution environment” are you using? The second generation, which is still in preview though, might fix these system calls. This is what we are currently using.

According to the docs:

The second generation execution environment provides full Linux compatibility rather than system call emulation.

1 Like

I tried but it also crash using gen2 (but thanks, I was not aware of this!). Do you think that hot reload / inotify can be part of the problem?

So I did some testing and it appears Google Cloud kills the application because the healthcheck fails. It test if the application is reachable on the given port. Since Phoenix runs on 127.0.0.1 in dev environment it isn’t available. So changing the ip configuration in config/dev.exs fixed the issue for me.

config :phoenix_cloud_run, PhoenixCloudRunWeb.Endpoint,
  # Binding to loopback ipv4 address prevents access from other machines.
  # Change to `ip: {0, 0, 0, 0}` to allow access from other machines.
- http: [ip: {127, 0, 0, 1}, port: 4000],
+ http: [ip: {0, 0, 0, 0}, port: 4000],
4 Likes

Even with the config/dev.ex update, for some reasons, this is not working for me. Do you use gen2 exec env? Anyway thanks for your help, I might have something else that is causing this crashes, I will investigate more in the next days.

I tested with both first-and second generation.

Did you change the port configuration on Cloud Run too? By default Cloud Run uses 8080 but Phoenix uses 4000 in dev environment.

1 Like

That was it, totally forgot about that! Thank you very much for your help.

1 Like