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

Failed to start server: ** (EXIT) :function_clause #61

Open
cpursley opened this issue May 5, 2024 · 3 comments
Open

Failed to start server: ** (EXIT) :function_clause #61

cpursley opened this issue May 5, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@cpursley
Copy link
Owner

cpursley commented May 5, 2024

Issue on master:

2024-05-03 14:10:57.440 [notice] Application my_app exited: MyApp.Application.start(:normal, []) returned an error: shutdown: failed to start child: WalEx.Supervisor
    ** (EXIT) shutdown: failed to start child: WalEx.Replication.Supervisor
        ** (EXIT) shutdown: failed to start child: WalEx.Replication.Server
            ** (EXIT) :function_clause

Originally posted by @cpursley in #57 (comment)

Ping @DaemonSnake

@cpursley cpursley added the bug Something isn't working label May 5, 2024
@DaemonSnake
Copy link
Contributor

I had this a few times when starting implementation, usually happens when a handle_result doesn't have a matching case.
One way I found to debug was to clone postgrex locally, use {"postgrex", path: "../postgres"} and modify the replication_connection module with the following patch

 lib/postgrex/replication_connection.ex | 12 +++++++++++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/lib/postgrex/replication_connection.ex b/lib/postgrex/replication_connection.ex
index 8fcde20..faccaf3 100644
--- a/lib/postgrex/replication_connection.ex
+++ b/lib/postgrex/replication_connection.ex
@@ -546,8 +546,18 @@ defmodule Postgrex.ReplicationConnection do
     end
   end

+  defp sapply(mod, fun, args) do
+    try do
+      apply(mod, fun, args)
+    rescue
+      error ->
+        Logger.error("REPLICATION_CONNECTION:" <> Exception.format(:error, error, __STACKTRACE__))
+        raise error
+    end
+  end
+
   defp handle(mod, fun, args, from, %{streaming: streaming} = s) do
-    case apply(mod, fun, args) do
+    case sapply(mod, fun, args) do
       {:noreply, mod_state} ->
         {:keep_state, %{s | state: {mod, mod_state}}}

with this change it give the full stacktrace and exception details for the :function_clause error

@DaemonSnake
Copy link
Contributor

DaemonSnake commented May 5, 2024

trying to reproduce locally but haven't found a way so far

@DaemonSnake
Copy link
Contributor

otherwise doing this as the last handle_result:

  @impl true
  def handle_result(results, state) do
    raise "Unexpected result: #{inspect(results)} for state: #{inspect(state)}"
  end

should help find what case is causing the crash

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants