-
Notifications
You must be signed in to change notification settings - Fork 305
Return proper error when getting tcp closed after fatal errors #765
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -1940,6 +1940,26 @@ defmodule QueryTest do | |
| end) =~ "** (Postgrex.Error) FATAL 57P01 (admin_shutdown)" | ||
| end | ||
|
|
||
| test "terminate backend during query returns FATAL error", context do | ||
| assert {:ok, pid} = P.start_link([idle_interval: 10] ++ context[:options]) | ||
|
|
||
| %Postgrex.Result{connection_id: connection_id} = Postgrex.query!(pid, "SELECT 42", []) | ||
|
|
||
| # Start a long-running query in a separate process so we can terminate the | ||
| # backend while it's executing. | ||
| task = | ||
| Task.async(fn -> | ||
| Postgrex.query(pid, "SELECT pg_sleep(10)", []) | ||
| end) | ||
|
|
||
| Process.sleep(100) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Instead of Process.sleep, you could setup a tracer and watch for Postgrex.query being returned. It should be deterministic. Would you like to give it a try?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I pushed a commit using tracer to detect when the query was sent via tracing the |
||
|
|
||
| assert [[true]] = query("SELECT pg_terminate_backend($1)", [connection_id]) | ||
|
|
||
| assert {:error, %Postgrex.Error{postgres: %{code: :admin_shutdown, severity: "FATAL"}}} = | ||
| Task.await(task, 5000) | ||
| end | ||
|
|
||
| test "terminate backend with socket", context do | ||
| Process.flag(:trap_exit, true) | ||
| socket = System.get_env("PG_SOCKET_DIR") || "/tmp" | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.