query cannot be terminated when client is suspended

From: "Caragea, George" <George(dot)Caragea(at)emc(dot)com>
To: "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: query cannot be terminated when client is suspended
Date: 2013-04-19 01:43:42
Message-ID: CD95EF5E.ACFB%george.caragea@emc.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Hello,
I tried the following scenario on PostgreSQL 9.4.2 on Linux:
1) Connect to a remote postgres database and run a long running query
e.g. psql -h vm5 -p 57001 warehouse -c 'select x.a from
generate_series(1, 100000000) as x(a);'
2) Suspend the client process by pressing CTRL-Z
3) In another session, get the backend PID from pg_stat_activity and run
pg_terminate_backend(PID)
or
pg_cancel_backend(PID)

The query hangs indeterminately and cannot be terminated.

Using strace, I see that the backend is stuck trying to send to the client
in the function internal_flush(), in send(). The backend does receive the
SIGINT or SIGTERM signal, but it is just restarting the system call.

sendto(9, "D\0\0\0\22\0\1\0\0\0\01017182365D\0\0\0\22\0\1\0\0\0\01017"...,
5392, 0, NULL, 0) = ? ERESTARTSYS (To be restarted)
--- SIGINT (Interrupt) @ 0 (0) ---
rt_sigreturn(0x2b85fc4234fc) = 44
sendto(9, "D\0\0\0\22\0\1\0\0\0\01017182365D\0\0\0\22\0\1\0\0\0\01017"...,
5392, 0, NULL, 0) = ? ERESTARTSYS (To be restarted)
--- SIGTERM (Terminated) @ 0 (0) ---
rt_sigreturn(0x2b85fc4234fc) = 44
sendto(9, "D\0\0\0\22\0\1\0\0\0\01017182365D\0\0\0\22\0\1\0\0\0\01017"...,
5392, 0, NULL, 0) = ? ERESTARTSYS (To be restarted)

We have several customers that see these "hanging" queries and have no way
of canceling them, and I suspect that this is the cause.

Has anyone else encountered this? Is there a way to cancel these queries,
or fix the problem in the code?

Thanks,
George

Browse pgsql-general by date

  From Date Subject
Next Message Albe Laurenz 2013-04-19 12:41:41 Re: dataset lock
Previous Message François Beausoleil 2013-04-18 22:09:00 Re: PQgetCopyData() failed - corruption?