GoulvenClech

GoulvenClech

GenServer servor error at deploy since Phoenix upgrade, may be related to EventStore?

Hi everyone,

I’m currently trying to upgrade :phoenix ~> 1.6.6 to ~> 1.6.15, :phoenix_live_dashboard ~> 0.6.4 to ~> 0.7, and :phoenix_pubsub ~> 2.0 to ~> 2.1.1.

I made a commit with only mix.exs & mix.lock upgrades, alongside some upgrading-related modifications (like changing function calls from Phoenix.LiveView.Helpers to Phoenix.Component or changing <LivePatch to <.link patch= kind of stuff), but no logic update or DB migration.

Everything works fine locally, but when I tried to deploy it with Fly.io on our staging website, I got this error :

Error: 2-12-12T09:29:25Z   [info]09:29:25.347 [error] GenServer {PhoenixApp.Auctions.EventStore.EventStore.Subscriptions.Registry, {"$all", "Auctions.Projectors.Auction"}} terminating
2022-12-12T09:29:25Z   [info]** (CaseClauseError) no case clause matching: {:error, %Postgrex.Error{connection_id: 3514705, message: nil, postgres: %{code: :undefined_column, file: "parse_relation.c", line: "3294", message: "column \"deleted_at\" does not exist", pg_code: "42703", position: "70", routine: "errorMissingColumn", severity: "ERROR", unknown: "ERROR"}, query: ["SELECT\n  stream_id,\n  stream_uuid,\n  stream_version,\n  created_at,\n  deleted_at\nFROM ", "public", ".streams\nWHERE stream_uuid = $1;\n"]}}

This error leads to an “Alloc Unhealthy because of failed task” error and breaks the deployment.

But we don’t have any deleted_at and created_at references in our code, nor in our DB. And I’ve tried redeploying the previous commit with success, leading me to believe this is Phoenix upgrade-related.

Here are the complete logs
Error: 2-12-12T09:29:25Z   [info]09:29:25.271 [error] GenServer {PhoenixApp.Auctions.EventStore.EventStore.Subscriptions.Registry, {"$all", "Auctions.Projectors.Auction"}} terminating
2022-12-12T09:29:25Z   [info]** (CaseClauseError) no case clause matching: {:error, %Postgrex.Error{connection_id: 3514704, message: nil, postgres: %{code: :undefined_column, file: "parse_relation.c", line: "3294", message: "column \"deleted_at\" does not exist", pg_code: "42703", position: "70", routine: "errorMissingColumn", severity: "ERROR", unknown: "ERROR"}, query: ["SELECT\n  stream_id,\n  stream_uuid,\n  stream_version,\n  created_at,\n  deleted_at\nFROM ", "public", ".streams\nWHERE stream_uuid = $1;\n"]}}
2022-12-12T09:29:25Z   [info]09:29:25.296 [debug] Subscription "Auctions.Projectors.Auction"@"$all" catching-up
2022-12-12T09:29:25Z   [info]09:29:25.296 [debug] PhoenixApp.Auctions.Projectors.Auction has successfully subscribed to event store
Error: 2-12-12T09:29:25Z   [info]09:29:25.307 [error] GenServer {PhoenixApp.Auctions.EventStore.EventStore.Subscriptions.Registry, {"$all", "Auctions.Projectors.Auction"}} terminating
2022-12-12T09:29:25Z   [info]** (CaseClauseError) no case clause matching: {:error, %Postgrex.Error{connection_id: 3514706, message: nil, postgres: %{code: :undefined_column, file: "parse_relation.c", line: "3294", message: "column \"deleted_at\" does not exist", pg_code: "42703", position: "70", routine: "errorMissingColumn", severity: "ERROR", unknown: "ERROR"}, query: ["SELECT\n  stream_id,\n  stream_uuid,\n  stream_version,\n  created_at,\n  deleted_at\nFROM ", "public", ".streams\nWHERE stream_uuid = $1;\n"]}}
2022-12-12T09:29:25Z   [info]    (eventstore 1.4.1) lib/event_store/subscriptions/subscription_fsm.ex:422: EventStore.Subscriptions.SubscriptionFsm.catch_up_from_stream/1
2022-12-12T09:29:25Z   [info]    (eventstore 1.4.1) lib/event_store/subscriptions/subscription_fsm.ex:98: EventStore.Subscriptions.SubscriptionFsm.transition/3
2022-12-12T09:29:25Z   [info]    (eventstore 1.4.1) lib/event_store/subscriptions/subscription.ex:186: EventStore.Subscriptions.Subscription.handle_cast/2
2022-12-12T09:29:25Z   [info]    (stdlib 3.17.2) gen_server.erl:695: :gen_server.try_dispatch/4
2022-12-12T09:29:25Z   [info]    (stdlib 3.17.2) gen_server.erl:771: :gen_server.handle_msg/6
Error: 2-12-12T09:29:25Z   [info]09:29:25.311 [error] GenServer {PhoenixApp.Auctions.Application, {PhoenixApp.Auctions.Application, Commanded.Event.Handler, "Auctions.Projectors.Auction"}} terminating
2022-12-12T09:29:25Z   [info]09:29:25.337 [debug] Subscription "Auctions.Projectors.Auction"@"$all" catching-up
2022-12-12T09:29:25Z   [info]09:29:25.337 [debug] PhoenixApp.Auctions.Projectors.Auction has successfully subscribed to event store
Error: 2-12-12T09:29:25Z   [info]09:29:25.347 [error] GenServer {PhoenixApp.Auctions.EventStore.EventStore.Subscriptions.Registry, {"$all", "Auctions.Projectors.Auction"}} terminating
2022-12-12T09:29:25Z   [info]** (CaseClauseError) no case clause matching: {:error, %Postgrex.Error{connection_id: 3514705, message: nil, postgres: %{code: :undefined_column, file: "parse_relation.c", line: "3294", message: "column \"deleted_at\" does not exist", pg_code: "42703", position: "70", routine: "errorMissingColumn", severity: "ERROR", unknown: "ERROR"}, query: ["SELECT\n  stream_id,\n  stream_uuid,\n  stream_version,\n  created_at,\n  deleted_at\nFROM ", "public", ".streams\nWHERE stream_uuid = $1;\n"]}}
2022-12-12T09:29:25Z   [info]    (eventstore 1.4.1) lib/event_store/subscriptions/subscription_fsm.ex:422: EventStore.Subscriptions.SubscriptionFsm.catch_up_from_stream/1
2022-12-12T09:29:25Z   [info]    (eventstore 1.4.1) lib/event_store/subscriptions/subscription_fsm.ex:98: EventStore.Subscriptions.SubscriptionFsm.transition/3
2022-12-12T09:29:25Z   [info]    (eventstore 1.4.1) lib/event_store/subscriptions/subscription.ex:186: EventStore.Subscriptions.Subscription.handle_cast/2
2022-12-12T09:29:25Z   [info]    (stdlib 3.17.2) gen_server.erl:695: :gen_server.try_dispatch/4
2022-12-12T09:29:25Z   [info]    (stdlib 3.17.2) gen_server.erl:771: :gen_server.handle_msg/6
Error: 2-12-12T09:29:25Z   [info]09:29:25.352 [error] GenServer {PhoenixApp.Auctions.Application, {PhoenixApp.Auctions.Application, Commanded.Event.Handler, "Auctions.Projectors.Auction"}} terminating
2022-12-12T09:29:25Z   [info]09:29:25.358 [debug] Monitored server Postgrex terminate due to: :shutdown
Notice: -12-12T09:29:25Z   [info]09:29:25.362 [notice] Application phoenix_app exited: shutdown
2022-12-12T09:29:25Z   [info][os_mon] memory supervisor port (memsup): Erlang has closed
2022-12-12T09:29:25Z   [info][os_mon] cpu supervisor port (cpu_sup): Erlang has closed
2022-12-12T09:29:26Z   [info]{"Kernel pid terminated",application_controller,"{application_terminated,phoenix_app,shutdown}"}
2022-12-12T09:29:26Z   [info]Kernel pid terminated (application_controller) ({application_terminated,phoenix_app,shutdown})
2022-12-12T09:29:27Z   [info]Crash dump is being written to: erl_crash.dump...done
2022-12-12T09:29:27Z   [info]Starting clean up.

Thank you for all your help, leads, or ideas that could help me :slight_smile:

Update:

It looks like it’s related to event_store. When I add {:eventstore, "== 1.1.0", override: true} to mix.exs, it fixes deploy. But it’s not an acceptable long-term fix.

I’m guessing it’s related to a recent breaking change, but the only one I see is in 1.2 ( Changelog — EventStore v1.4.8 ) with EventStore.Tasks.Init.exec/3 deprecated for EventStore.Tasks.Init.exec/1 and EventStore.Tasks.Init.exec/2. But fixing that still give me :

 v428 is being deployed
cd3fd680: cdg running healthy
--> v428 failed - Failed due to unhealthy allocations - rolling back to job version 427 and deploying as v429 

--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort

In any case, everything still works locally; the error still occurs at deployment.

Any other ideas?

Marked As Solved

GoulvenClech

GoulvenClech

Hi @al2o3cr , thanks for identifying the problem and sending me the related documentation. However, the solution was not exactly what is documented… I’ll go over my failed attempts and finally give my solution.

:no_entry: Migrating with mix
We use mix release so, as documented, we don’t have mix available. Leading to the second solution documented :

:no_entry: Migrating using a helper function
I don’t understand this documented solution; we should use the command eval "MyApp.ReleaseTasks.migrate_event_store()" inside the release folder… Which does not exist because the release fails without the migration of the event store!

cd3fd680: cdg running healthy
--> v428 failed - Failed due to unhealthy allocations - rolling back to job version 427 and deploying as v429 

--> Troubleshooting guide at https://fly.io/docs/getting-started/troubleshooting/
Error abort

To try to do the migration during the deployment, I thought of calling it in my DockerFile:

:no_entry: Migrating with mix in docker
mix event_store.migrate failed with the error :nofile

 => ERROR [build  8/18] RUN mix event_store.migrate                                                                                                                                                 3.0s
------
 > [build  8/18] RUN mix event_store.migrate:
#19 1.498 Generated my_app app
#19 2.903 ** (Mix) Could not load MyApp.Auctions.EventStore, error: :nofile. Please configure your app accordingly or pass a event store with the -e option.
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c mix event_store.migrate]: exit code: 1

Same error with the -e option

 => ERROR [build  8/18] RUN mix event_store.migrate -e MyApp.Auctions.EventStore                                                                                                             2.6s
------                                                                                                                                                                                                   
 > [build  8/18] RUN mix event_store.migrate -e MyApp.Auctions.EventStore:
#19 1.469 Generated my_app app
#19 2.556 ** (Mix) Could not load MyApp.Auctions.EventStore, error: :nofile. Please configure your app accordingly or pass a event store with the -e option.
------
Error failed to fetch an image or build from source: error building: executor failed running [/bin/sh -c mix event_store.migrate -e MyApp.Auctions.EventStore]: exit code: 1

:white_check_mark: Migrating using a helper function inside Release.migrate()
So I finally thought of using the release function that we pass to Fly.

Fly.io call this command [deploy] release_command = "/app/bin/my_app eval MyApp.Release.migrate" at every deployment, which ensure everything started, load the app, and call Ecto.Migrator.with_repo().

I added a call to my helper function MyApp.Release.migrate_evenstore and voilà :tada:

Thanks everyone for the help on this :slightly_smiling_face: and sorry for not having updated sooner!

Also Liked

al2o3cr

al2o3cr

There is a required database migration when upgrading from 1.1.0 to 1.2.0 - among other things, it adds the deleted_at column that your error message says is missing:

https://github.com/commanded/eventstore/blob/master/priv/event_store/migrations/v1.2.0.sql#L67

More detail about running `event_store` migrations`

Where Next?

Popular in Questions Top

vegabook
I’m brand new to Phoenix and I have stripped one of the demo applications to the bone. I just want to get an svg up on the screen. Here i...
New
9mm
I am constructing a JSON object (map) and I need to conditionally set a field. I’m trying to write proper elixir-way code… and I’m at a l...
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Patoshizzle
After calling mix ecto.create I get this error: 17:00:32.162 [error] GenServer #PID&lt;0.412.0&gt; terminating ** (Postgrex.Error) FATAL...
New

Other popular topics Top

rms.mrcs
Hi, I need to transform a list of numbers into a map where the keys are the indexes and the values are the original values of the list. ...
New
grych
Hi folks, Few months ago I have announced the proof-of-concept of the library to manipulate the browsers DOM objects directly from Elixi...
639 54006 488
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
vonH
In asking this question I am more interested about the expressiveness of the language itself and less concerned about the availability of...
New
gshaw
What is the idiomatic way of matching for not nil in Elixir? E.g., First way: defp halt_if_not_signed_in(conn, signed_in_account) when...
New
sen
Hi All, I set a environment variables in dev.exs , like below code. when i start server, how can i set the ${enable} value? thanks. d...
New

We're in Beta

About us Mission Statement