Обсуждение: BUG #15076: postmaster crashes unexpectedly when using up arrow keyin psql command

Поиск
Список
Период
Сортировка

BUG #15076: postmaster crashes unexpectedly when using up arrow keyin psql command

От
PG Bug reporting form
Дата:
The following bug has been logged on the website:

Bug reference:      15076
Logged by:          Mingchun Zhao
Email address:      mzhao@insight-tec.co.jp
PostgreSQL version: 9.3.20
Operating system:   Windows
Description:

steps to reproduce:

(1) run psql.exe in a Windows Command Prompt
(2) execute a SQL with more than one page of results, e.g. `show all;`
(3) press Ctrl + C to break it on the first page
(4) press up arrow key to try to execute the previous SQL of the step(2)
again
(5) Occasionally, it will show you nothing about the SQL, then you can try
to input a character ';' and press Enter key, the PostgreSQL will crash
unexpectedly



Re: BUG #15076: postmaster crashes unexpectedly when using up arrowkey in psql command

От
"David G. Johnston"
Дата:


On Wednesday, February 21, 2018, PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      15076
Logged by:          Mingchun Zhao
Email address:      mzhao@insight-tec.co.jp
PostgreSQL version: 9.3.20
Operating system:   Windows
Description:

steps to reproduce:

(1) run psql.exe in a Windows Command Prompt
(2) execute a SQL with more than one page of results, e.g. `show all;`
(3) press Ctrl + C to break it on the first page
(4) press up arrow key to try to execute the previous SQL of the step(2)
again
(5) Occasionally, it will show you nothing about the SQL, then you can try
to input a character ';' and press Enter key, the PostgreSQL will crash
unexpectedly


It would help to explain what you actually see in step 5 instead of just saying crash.  In particular is the "failure" in the server or client?

David J. 

Re: BUG #15076: postmaster crashes unexpectedly when using up arrow key in psql command

От
Tom Lane
Дата:
"David G. Johnston" <david.g.johnston@gmail.com> writes:
>> The following bug has been logged on the website:
>> (4) press up arrow key to try to execute the previous SQL of the step(2)
>> again
>> (5) Occasionally, it will show you nothing about the SQL, then you can try
>> to input a character ';' and press Enter key, the PostgreSQL will crash
>> unexpectedly

> It would help to explain what you actually see in step 5 instead of just
> saying crash.  In particular is the "failure" in the server or client?

I'd lay long odds that what's being described is a psql crash not a
server crash, and furthermore that the problem is in libreadline
(which is what would be handling up-arrow response).  We've heard
reports before of flaky readline behavior on Windows.  I failed to
find an exact match to this report in a moment's worth of trawling
the archives, though I did find for instance

https://www.postgresql.org/message-id/flat/6a2534f3-4359-617d-d314-17174454eb6d%40orange.fr

I think the questions to ask are around where did this copy of
psql.exe come from, and what version of readline is included in
it, and whether that's up-to-date.

            regards, tom lane


Re: BUG #15076: postmaster crashes unexpectedly when using up arrowkey in psql command

От
趙明春
Дата:
​​Hi, david,

> It would help to explain what you actually see in step 5 instead of just saying crash.  In particular is the "failure" in the server or client?

It looks like the postmaster has received signal 2 in step 5, the following is the corresponding PostgreSQL log:
==
0000: 2018-02-19 15:37:34 JST [3492]: [65-1] user = ,db = ,remote =  app =  DEBUG:  postmaster received signal 2
00000: 2018-02-19 15:37:34 JST [3492]: [66-1] user = ,db = ,remote =  app =  LOG:  received fast shutdown request
00000: 2018-02-19 15:37:34 JST [3492]: [67-1] user = ,db = ,remote =  app =  LOG:  aborting any active transactions
==

​Regards,
Mingchun​


2018-02-22 12:29 GMT+09:00 David G. Johnston <david.g.johnston@gmail.com>:


On Wednesday, February 21, 2018, PG Bug reporting form <noreply@postgresql.org> wrote:
The following bug has been logged on the website:

Bug reference:      15076
Logged by:          Mingchun Zhao
Email address:      mzhao@insight-tec.co.jp
PostgreSQL version: 9.3.20
Operating system:   Windows
Description:

steps to reproduce:

(1) run psql.exe in a Windows Command Prompt
(2) execute a SQL with more than one page of results, e.g. `show all;`
(3) press Ctrl + C to break it on the first page
(4) press up arrow key to try to execute the previous SQL of the step(2)
again
(5) Occasionally, it will show you nothing about the SQL, then you can try
to input a character ';' and press Enter key, the PostgreSQL will crash
unexpectedly


It would help to explain what you actually see in step 5 instead of just saying crash.  In particular is the "failure" in the server or client?

David J. 

Re: BUG #15076: postmaster crashes unexpectedly when using up arrowkey in psql command

От
趙明春
Дата:
Hi, Tom,

You mean that the up-arrow key operation in psql.exe may send a SIGINT(or SIGTERM) signal to server(postmaster) unexpectedly?

Thanks,
Mingchun


-----------------------------------------------------------------------------------
 Insight Technology, Inc.  Mingchun Zhao,  趙 明春(チョウ メイシュン)
  EbisBusinessTower 5F, 1-19-19, Shibuya-ku, Tokyo
  TEL  : +81-3-5475-1452            FAX : +81-3-5475-1451
-----------------------------------------------------------------------------------


2018-02-22 13:06 GMT+09:00 Tom Lane <tgl@sss.pgh.pa.us>:
"David G. Johnston" <david.g.johnston@gmail.com> writes:
>> The following bug has been logged on the website:
>> (4) press up arrow key to try to execute the previous SQL of the step(2)
>> again
>> (5) Occasionally, it will show you nothing about the SQL, then you can try
>> to input a character ';' and press Enter key, the PostgreSQL will crash
>> unexpectedly

> It would help to explain what you actually see in step 5 instead of just
> saying crash.  In particular is the "failure" in the server or client?

I'd lay long odds that what's being described is a psql crash not a
server crash, and furthermore that the problem is in libreadline
(which is what would be handling up-arrow response).  We've heard
reports before of flaky readline behavior on Windows.  I failed to
find an exact match to this report in a moment's worth of trawling
the archives, though I did find for instance

https://www.postgresql.org/message-id/flat/6a2534f3-4359-617d-d314-17174454eb6d%40orange.fr

I think the questions to ask are around where did this copy of
psql.exe come from, and what version of readline is included in
it, and whether that's up-to-date.

                        regards, tom lane

Re: BUG #15076: postmaster crashes unexpectedly when using up arrowkey in psql command

От
Michael Paquier
Дата:
On Thu, Feb 22, 2018 at 03:57:53PM +0900, 趙明春 wrote:
> You mean that the up-arrow key operation in psql.exe may send a SIGINT(or
> SIGTERM) signal to server(postmaster) unexpectedly?

No.  What Tom means here is that you are likely mistaking what you think
is a server crash by a client crash, and that the version of libreadline
your psql version is linked to is buggy and unable to handle that
properly.  psql has no control on the server itself.
--
Michael

Вложения

Re: BUG #15076: postmaster crashes unexpectedly when using up arrowkey in psql command

От
趙明春
Дата:
Hi, Michael, Thanks. I got what you mean.

Anyway, the postmaster was received signal 2 in step 5 as below.

(1) run psql.exe in a Windows Command Prompt
(2) execute a SQL with more than one page of results, e.g. `show all;`
(3) press Ctrl + C to break it on the first page
(4) press up arrow key to try to execute the previous SQL of the step(2) again
(5) Occasionally, it will show you nothing about the SQL, then you can try to input a character ';' and press Enter key, the PostgreSQL will crash unexpectedly

So, Let me change my question:
If I started the PostgreSQL by pg_ctl command in the same Windows command prompt,
Is it possible that pressing Ctrl + C on psql to break query(not session) will send SIGINT to postmaster process unexpectedly?

Best Regards,
Mingchun

-----------------------------------------------------------------------------------
 Insight Technology, Inc.  Mingchun Zhao,  趙 明春(チョウ メイシュン)
  EbisBusinessTower 5F, 1-19-19, Shibuya-ku, Tokyo
  TEL  : +81-3-5475-1452            FAX : +81-3-5475-1451
-----------------------------------------------------------------------------------


2018-02-22 16:57 GMT+09:00 Michael Paquier <michael@paquier.xyz>:
On Thu, Feb 22, 2018 at 03:57:53PM +0900, 趙明春 wrote:
> You mean that the up-arrow key operation in psql.exe may send a SIGINT(or
> SIGTERM) signal to server(postmaster) unexpectedly?

No.  What Tom means here is that you are likely mistaking what you think
is a server crash by a client crash, and that the version of libreadline
your psql version is linked to is buggy and unable to handle that
properly.  psql has no control on the server itself.
--
Michael

Re: BUG #15076: postmaster crashes unexpectedly when using up arrow key in psql command

От
Tom Lane
Дата:
=?UTF-8?B?6LaZ5piO5pil?= <mzhao@insight-tec.co.jp> writes:
> So, Let me change my question:
> If I started the PostgreSQL by pg_ctl command in the same Windows command
> prompt,
> Is it possible that pressing Ctrl + C on psql to break query(not session)
> will send SIGINT to postmaster process unexpectedly?

I don't know much about Windows signal processing, but the log entries you
show certainly look like that's what happened.

On Unix-ish machines it's normal for control-C to send a SIGINT to every
process that's in the terminal's process group --- *not* just the
foreground process.  So if you launch the postmaster manually you'd better
make sure that it gets dissociated from the terminal, or you're at risk
of killing it accidentally.  (Or, if you want to leave it connected to
that terminal, you use another window to run psql etc.)  It seems that
something similar is happening on your Windows setup.  I don't know
the rules for process/terminal association on Windows, so I can't suggest
what's the right way to do it.  I will say though that most people
run the postmaster as a background service on Windows, rather than
launching it manually.

            regards, tom lane


Re: BUG #15076: postmaster crashes unexpectedly when using up arrowkey in psql command

От
Magnus Hagander
Дата:


On Thu, Feb 22, 2018 at 4:12 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
趙明春 <mzhao@insight-tec.co.jp> writes:
> So, Let me change my question:
> If I started the PostgreSQL by pg_ctl command in the same Windows command
> prompt,
> Is it possible that pressing Ctrl + C on psql to break query(not session)
> will send SIGINT to postmaster process unexpectedly?

I don't know much about Windows signal processing, but the log entries you
show certainly look like that's what happened.

Yes, this is unfortunately exactly how it works on Windows.

There is on way to intercept the Ctrl-C and have it not delivered to *all* processes out of the same session. It can only be added or removed for the current process (which psql does). So it gets delivered to the backends which call pg_console_handler, which emulates SIGINT.


On Unix-ish machines it's normal for control-C to send a SIGINT to every
process that's in the terminal's process group --- *not* just the
foreground process.  So if you launch the postmaster manually you'd better
make sure that it gets dissociated from the terminal, or you're at risk
of killing it accidentally.  (Or, if you want to leave it connected to
that terminal, you use another window to run psql etc.)  It seems that
something similar is happening on your Windows setup.  I don't know
the rules for process/terminal association on Windows, so I can't suggest
what's the right way to do it.  I will say though that most people
run the postmaster as a background service on Windows, rather than
launching it manually.

AFAIC Windows has no way to disassociate a process with a console window in a similar way. 


--

Re: BUG #15076: postmaster crashes unexpectedly when using up arrowkey in psql command

От
趙明春
Дата:
Hi, Tom and Magnus,

Thanks for your information for this issue.

> AFAIC Windows has no way to disassociate a process with a console window in a similar way.

Can this be a solution for this issue to add an option CREATE_NEW_PROCESS_GROUP to CreateProcess() function into pg_ctl.exe to start postgres.exe process?

>  I will say though that most people run the postmaster as a background service on Windows, rather than launching it manually.

Unfortunately, we also met this issue, with poor reproducibility, when we running the postmaster as Windows Service.
Maybe this is another story than launching it manually by pg_ctl.exe.
I will update you if I get any new information.

BEST,

-----------------------------------------------------------------------------------
 Insight Technology, Inc.  Mingchun Zhao,  趙 明春(チョウ メイシュン)
  EbisBusinessTower 5F, 1-19-19, Shibuya-ku, Tokyo
  TEL  : +81-3-5475-1452            FAX : +81-3-5475-1451
-----------------------------------------------------------------------------------


2018-02-23 4:35 GMT+09:00 Magnus Hagander <magnus@hagander.net>:


On Thu, Feb 22, 2018 at 4:12 PM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
趙明春 <mzhao@insight-tec.co.jp> writes:
> So, Let me change my question:
> If I started the PostgreSQL by pg_ctl command in the same Windows command
> prompt,
> Is it possible that pressing Ctrl + C on psql to break query(not session)
> will send SIGINT to postmaster process unexpectedly?

I don't know much about Windows signal processing, but the log entries you
show certainly look like that's what happened.

Yes, this is unfortunately exactly how it works on Windows.

There is on way to intercept the Ctrl-C and have it not delivered to *all* processes out of the same session. It can only be added or removed for the current process (which psql does). So it gets delivered to the backends which call pg_console_handler, which emulates SIGINT.


On Unix-ish machines it's normal for control-C to send a SIGINT to every
process that's in the terminal's process group --- *not* just the
foreground process.  So if you launch the postmaster manually you'd better
make sure that it gets dissociated from the terminal, or you're at risk
of killing it accidentally.  (Or, if you want to leave it connected to
that terminal, you use another window to run psql etc.)  It seems that
something similar is happening on your Windows setup.  I don't know
the rules for process/terminal association on Windows, so I can't suggest
what's the right way to do it.  I will say though that most people
run the postmaster as a background service on Windows, rather than
launching it manually.

AFAIC Windows has no way to disassociate a process with a console window in a similar way. 


--

Re: BUG #15076: postmaster crashes unexpectedly when using up arrowkey in psql command

От
Magnus Hagander
Дата:
On Fri, Feb 23, 2018 at 3:16 AM, 趙明春 <mzhao@insight-tec.co.jp> wrote:
Hi, Tom and Magnus,

Thanks for your information for this issue.

> AFAIC Windows has no way to disassociate a process with a console window in a similar way.

Can this be a solution for this issue to add an option CREATE_NEW_PROCESS_GROUP to CreateProcess() function into pg_ctl.exe to start postgres.exe process?

That definitely sounds like it should be worth a try. 


>  I will say though that most people run the postmaster as a background service on Windows, rather than launching it manually.

Unfortunately, we also met this issue, with poor reproducibility, when we running the postmaster as Windows Service.
Maybe this is another story than launching it manually by pg_ctl.exe.
I will update you if I get any new information.


That sounds very strange. I'm not saying you're not running into an issue there, but my guess would be you're actually running into a different problem (which may have similar symptoms).

//Magnus
 

Re: BUG #15076: postmaster crashes unexpectedly when using up arrowkey in psql command

От
趙明春
Дата:
Hi, Magnus,

> That definitely sounds like it should be worth a try. 

Sounds good. I'll try to make a patch for it.

> That sounds very strange. I'm not saying you're not running into an issue there, but my guess would be you're actually running into a different problem (which may have similar symptoms).

I see, I'll look into the way to reproduce the same symptom.

Thanks,
Mingchun

-----------------------------------------------------------------------------------
 Insight Technology, Inc.  Mingchun Zhao,  趙 明春(チョウ メイシュン)
  EbisBusinessTower 5F, 1-19-19, Shibuya-ku, Tokyo
  TEL  : +81-3-5475-1452            FAX : +81-3-5475-1451
-----------------------------------------------------------------------------------


2018-02-25 7:09 GMT+09:00 Magnus Hagander <magnus@hagander.net>:
On Fri, Feb 23, 2018 at 3:16 AM, 趙明春 <mzhao@insight-tec.co.jp> wrote:
Hi, Tom and Magnus,

Thanks for your information for this issue.

> AFAIC Windows has no way to disassociate a process with a console window in a similar way.

Can this be a solution for this issue to add an option CREATE_NEW_PROCESS_GROUP to CreateProcess() function into pg_ctl.exe to start postgres.exe process?

That definitely sounds like it should be worth a try. 


>  I will say though that most people run the postmaster as a background service on Windows, rather than launching it manually.

Unfortunately, we also met this issue, with poor reproducibility, when we running the postmaster as Windows Service.
Maybe this is another story than launching it manually by pg_ctl.exe.
I will update you if I get any new information.


That sounds very strange. I'm not saying you're not running into an issue there, but my guess would be you're actually running into a different problem (which may have similar symptoms).

//Magnus