pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #17698: On SIGTERM, psql terminates, but leaves the statement running
5+ messages / 5 participants
[nested] [flat]

* BUG #17698: On SIGTERM, psql terminates, but leaves the statement running
@ 2022-11-25 18:01 PG Bug reporting form <noreply@postgresql.org>
  2023-01-16 15:14 ` Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running Alvaro Herrera <alvherre@alvh.no-ip.org>
  0 siblings, 1 reply; 5+ messages in thread

From: PG Bug reporting form @ 2022-11-25 18:01 UTC (permalink / raw)
  To: pgsql-bugs@lists.postgresql.org; +Cc: dastapov@gmail.com

The following bug has been logged on the website:

Bug reference:      17698
Logged by:          Dmitry Astapov
Email address:      dastapov@gmail.com
PostgreSQL version: 14.2
Operating system:   CentOS 7
Description:        

Reproduction: start psql, launch a query that will take a while (I used
'select pg_sleep(1234)'), then from another terminal do "kill -TERM <pid of
psql>".
Psql would be terminated, but query would not be, and will keep running
until TCP timeout kicks in and kills the stale connection.

SIGINT, on the other hand, will cause psql will terminate the current
statement.

Perhaps psql could have a SIGTERM handler that does roughly what SIGINT
handler does before terminating the whole process, and would cancel the
current statement (if any)?



^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running
  2022-11-25 18:01 BUG #17698: On SIGTERM, psql terminates, but leaves the statement running PG Bug reporting form <noreply@postgresql.org>
@ 2023-01-16 15:14 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
  2023-01-16 19:44   ` Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running Dmitry Astapov <dastapov@gmail.com>
  2023-05-22 17:04   ` Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running Tristan Partin <tristan@neon.tech>
  0 siblings, 2 replies; 5+ messages in thread

From: Alvaro Herrera @ 2023-01-16 15:14 UTC (permalink / raw)
  To: dastapov@gmail.com; pgsql-bugs@lists.postgresql.org

On 2022-Nov-25, PG Bug reporting form wrote:

> Reproduction: start psql, launch a query that will take a while (I
> used 'select pg_sleep(1234)'), then from another terminal do
> "kill -TERM <pid of psql>".  Psql would be terminated, but query would
> not be, and will keep running until TCP timeout kicks in and kills the
> stale connection.
> 
> SIGINT, on the other hand, will cause psql will terminate the current
> statement.
> 
> Perhaps psql could have a SIGTERM handler that does roughly what
> SIGINT handler does before terminating the whole process, and would
> cancel the current statement (if any)?

Sure.  I doubt we want to wait until a reply to the cancel request is
obtained, but we could have the sigterm handler at least send it before
terminating.

Why do you send SIGTERM to psql anyway?

-- 
Álvaro Herrera         PostgreSQL Developer  —  https://www.EnterpriseDB.com/
"Thou shalt not follow the NULL pointer, for chaos and madness await
thee at its end." (2nd Commandment for C programmers)





^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running
  2022-11-25 18:01 BUG #17698: On SIGTERM, psql terminates, but leaves the statement running PG Bug reporting form <noreply@postgresql.org>
  2023-01-16 15:14 ` Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2023-01-16 19:44   ` Dmitry Astapov <dastapov@gmail.com>
  2023-01-16 20:34     ` Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running Pavel Stehule <pavel.stehule@gmail.com>
  1 sibling, 1 reply; 5+ messages in thread

From: Dmitry Astapov @ 2023-01-16 19:44 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; +Cc: pgsql-bugs@lists.postgresql.org

On Mon, Jan 16, 2023 at 3:21 PM Alvaro Herrera <alvherre@alvh.no-ip.org>
wrote:

> On 2022-Nov-25, PG Bug reporting form wrote:
> >
> > Perhaps psql could have a SIGTERM handler that does roughly what
> > SIGINT handler does before terminating the whole process, and would
> > cancel the current statement (if any)?
>
> Sure.  I doubt we want to wait until a reply to the cancel request is
> obtained, but we could have the sigterm handler at least send it before
> terminating.
>
> Why do you send SIGTERM to psql anyway?
>
>
The way the story was told to me by the user, they started psql from inside
the neovim session and then cancelled it with Ctrl-C. Apparently, neovim
(unlike, say, vim) sends SIGTERM to the child process in this case (whereas
vim will send SIGINT).


-- 
D. Astapov

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running
  2022-11-25 18:01 BUG #17698: On SIGTERM, psql terminates, but leaves the statement running PG Bug reporting form <noreply@postgresql.org>
  2023-01-16 15:14 ` Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running Alvaro Herrera <alvherre@alvh.no-ip.org>
  2023-01-16 19:44   ` Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running Dmitry Astapov <dastapov@gmail.com>
@ 2023-01-16 20:34     ` Pavel Stehule <pavel.stehule@gmail.com>
  0 siblings, 0 replies; 5+ messages in thread

From: Pavel Stehule @ 2023-01-16 20:34 UTC (permalink / raw)
  To: Dmitry Astapov <dastapov@gmail.com>; +Cc: Alvaro Herrera <alvherre@alvh.no-ip.org>; pgsql-bugs@lists.postgresql.org

po 16. 1. 2023 v 20:45 odesílatel Dmitry Astapov <dastapov@gmail.com>
napsal:

>
>
> On Mon, Jan 16, 2023 at 3:21 PM Alvaro Herrera <alvherre@alvh.no-ip.org>
> wrote:
>
>> On 2022-Nov-25, PG Bug reporting form wrote:
>> >
>> > Perhaps psql could have a SIGTERM handler that does roughly what
>> > SIGINT handler does before terminating the whole process, and would
>> > cancel the current statement (if any)?
>>
>> Sure.  I doubt we want to wait until a reply to the cancel request is
>> obtained, but we could have the sigterm handler at least send it before
>> terminating.
>>
>> Why do you send SIGTERM to psql anyway?
>>
>>
> The way the story was told to me by the user, they started psql from
> inside the neovim session and then cancelled it with Ctrl-C. Apparently,
> neovim (unlike, say, vim) sends SIGTERM to the child process in this case
> (whereas vim will send SIGINT).
>

I think there may be a bug - I am not able to reproduce it, but sometimes I
can crash psql by CTRL-C too.

Regards

Pavel




>
>
> --
> D. Astapov
>

^ permalink  raw  reply  [nested|flat] 5+ messages in thread

* Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running
  2022-11-25 18:01 BUG #17698: On SIGTERM, psql terminates, but leaves the statement running PG Bug reporting form <noreply@postgresql.org>
  2023-01-16 15:14 ` Re: BUG #17698: On SIGTERM, psql terminates, but leaves the statement running Alvaro Herrera <alvherre@alvh.no-ip.org>
@ 2023-05-22 17:04   ` Tristan Partin <tristan@neon.tech>
  1 sibling, 0 replies; 5+ messages in thread

From: Tristan Partin @ 2023-05-22 17:04 UTC (permalink / raw)
  To: Alvaro Herrera <alvherre@alvh.no-ip.org>; dastapov@gmail.com; pgsql-bugs@lists.postgresql.org

On Mon Jan 16, 2023 at 9:14 AM CST, Alvaro Herrera wrote:
> On 2022-Nov-25, PG Bug reporting form wrote:
>
> > Reproduction: start psql, launch a query that will take a while (I
> > used 'select pg_sleep(1234)'), then from another terminal do
> > "kill -TERM <pid of psql>".  Psql would be terminated, but query would
> > not be, and will keep running until TCP timeout kicks in and kills the
> > stale connection.
> > 
> > SIGINT, on the other hand, will cause psql will terminate the current
> > statement.
> > 
> > Perhaps psql could have a SIGTERM handler that does roughly what
> > SIGINT handler does before terminating the whole process, and would
> > cancel the current statement (if any)?
>
> Sure.  I doubt we want to wait until a reply to the cancel request is
> obtained, but we could have the sigterm handler at least send it before
> terminating.

I am currently working on a patch for this.

-- 
Tristan Partin
Neon (https://neon.tech)





^ permalink  raw  reply  [nested|flat] 5+ messages in thread


end of thread, other threads:[~2023-05-22 17:04 UTC | newest]

Thread overview: 5+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2022-11-25 18:01 BUG #17698: On SIGTERM, psql terminates, but leaves the statement running PG Bug reporting form <noreply@postgresql.org>
2023-01-16 15:14 ` Alvaro Herrera <alvherre@alvh.no-ip.org>
2023-01-16 19:44   ` Dmitry Astapov <dastapov@gmail.com>
2023-01-16 20:34     ` Pavel Stehule <pavel.stehule@gmail.com>
2023-05-22 17:04   ` Tristan Partin <tristan@neon.tech>

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox