pg.ddx.io  pgsql-bugs@postgresql.org mailing list archive  
help / color / mirror / Atom feed
BUG #7643: Issuing a shutdown request while server startup leads to server hang
8+ messages / 3 participants
[nested] [flat]

* BUG #7643: Issuing a shutdown request while server startup leads to server hang
@ 2012-11-08 18:15 haribabu.kommi@huawei.com
  2012-11-19 19:32 ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 8+ messages in thread

From: haribabu.kommi@huawei.com @ 2012-11-08 18:15 UTC (permalink / raw)
  To: pgsql-bugs

The following bug has been logged on the website:

Bug reference:      7643
Logged by:          Haribabu
Email address:      haribabu.kommi@huawei.com
PostgreSQL version: 9.2.1
Operating system:   Suse Linux 10.2
Description:        

Problem Reproduction:
1. Add recovery.conf to the database directory.
2. Start the server
3. Issue the shutdown request 
and the shutdown request timing should be such that below server logs should
print.

Log:

./postgres -D data -p 3335
LOG:  database system was shut down in recovery at 2012-11-08 19:42:42 IST
LOG:  entering standby mode
LOG:  received fast shutdown request
LOG:  consistent recovery state reached at 0/17D0700
LOG:  record with zero length at 0/17D0700

Problem reproduced in 9.3 head.

I think the following things are leading to the problem:

1. The postmaster is queued up with the following signals in the order of
SIGINT (shutdown) and SIGUSR1 (Here we create bgwriter and checkpoint) and
the current state of postmaster is PM_STARTUP.

we are creating the bgwriter and checkpoint after processing the shutdown
request, because of this reason no one is there is to send the SIGTERM to
bgwriter and checkpoint.










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

* Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang
  2012-11-08 18:15 BUG #7643: Issuing a shutdown request while server startup leads to server hang haribabu.kommi@huawei.com
@ 2012-11-19 19:32 ` Tom Lane <tgl@sss.pgh.pa.us>
  2012-11-20 04:31   ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Hari Babu <haribabu.kommi@huawei.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Tom Lane @ 2012-11-19 19:32 UTC (permalink / raw)
  To: haribabu.kommi@huawei.com; +Cc: pgsql-bugs

haribabu.kommi@huawei.com writes:
> Problem Reproduction:
> 1. Add recovery.conf to the database directory.
> 2. Start the server
> 3. Issue the shutdown request 
> and the shutdown request timing should be such that below server logs should
> print.

> Log:

> ./postgres -D data -p 3335
> LOG:  database system was shut down in recovery at 2012-11-08 19:42:42 IST
> LOG:  entering standby mode
> LOG:  received fast shutdown request
> LOG:  consistent recovery state reached at 0/17D0700
> LOG:  record with zero length at 0/17D0700

> Problem reproduced in 9.3 head.

After further investigation, I can't reproduce this and I don't believe
your patch fixes it.  What happens when I try this is

* postmaster gets SIGINT, sends SIGTERM to startup process

* startup process exits with exit(1)

* postmaster sees that as a startup crash and exits, per the first
test in reaper()

So the log trace I'm getting looks like

LOG:  received fast shutdown request
LOG:  startup process (PID 9772) exited with exit code 1
LOG:  aborting startup due to startup process failure

Now, transitioning to PM_WAIT_BACKENDS state earlier, as your patch
proposes, might make the log look a bit nicer because the logic in
reaper() wouldn't think the exit was a "crash".  But it's not going to
have anything to do with whether the startup process exits on the signal
or not.  What seems to have happened for you is that the startup process
ignored the SIGTERM signal, but it's not at all obvious why.

We're going to need more details about how to reproduce this.
I speculate it might have something to do with the specific
restore_command you're using.

			regards, tom lane




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

* Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang
  2012-11-08 18:15 BUG #7643: Issuing a shutdown request while server startup leads to server hang haribabu.kommi@huawei.com
  2012-11-19 19:32 ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Tom Lane <tgl@sss.pgh.pa.us>
@ 2012-11-20 04:31   ` Hari Babu <haribabu.kommi@huawei.com>
  2012-11-20 21:00     ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 8+ messages in thread

From: Hari Babu @ 2012-11-20 04:31 UTC (permalink / raw)
  To: 'Tom Lane' <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

>haribabu.kommi@huawei.com writes:
> Problem Reproduction:
> 1. Add recovery.conf to the database directory.
> 2. Start the server
> 3. Issue the shutdown request 
> and the shutdown request timing should be such that below server logs
should
> print.

> Log:

> ./postgres -D data -p 3335
> LOG:  database system was shut down in recovery at 2012-11-08 19:42:42 IST
> LOG:  entering standby mode
> LOG:  received fast shutdown request
> LOG:  consistent recovery state reached at 0/17D0700
> LOG:  record with zero length at 0/17D0700

> Problem reproduced in 9.3 head.

>After further investigation, I can't reproduce this and I don't believe
>your patch fixes it.  What happens when I try this is

>* postmaster gets SIGINT, sends SIGTERM to startup process

>* startup process exits with exit(1)

>* postmaster sees that as a startup crash and exits, per the first
>test in reaper()

>So the log trace I'm getting looks like

>LOG:  received fast shutdown request
>LOG:  startup process (PID 9772) exited with exit code 1
>LOG:  aborting startup due to startup process failure

>Now, transitioning to PM_WAIT_BACKENDS state earlier, as your patch
>proposes, might make the log look a bit nicer because the logic in
>reaper() wouldn't think the exit was a "crash".  But it's not going to
>have anything to do with whether the startup process exits on the signal
>or not.  What seems to have happened for you is that the startup process
>ignored the SIGTERM signal, but it's not at all obvious why.

>We're going to need more details about how to reproduce this.
>I speculate it might have something to do with the specific
>restore_command you're using.

The problem occurs only when active server is restarting by just adding a
recovery.conf file to the data directory. 
No need of specifying any restore command. or the standby server restart
also can lead to this problem. 

The startup process sends "PMSIGNAL_RECOVERY_STARTED" to postmaster only
incase of "InArchiveRecovery" flag is enabled. 
The SIGINT signal should reach postmaster before the
"PMSIGNAL_RECOVERY_STARTED" sent by the startup process.

with the following code change in the startupXlog function, the issue can
reproduce very easily. 

        if (InArchiveRecovery && IsUnderPostmaster) 
        { 
                PublishStartupProcessInformation(); 
                SetForwardFsyncRequests(); 
                kill (PostmasterPid, SIGINT); 
                SendPostmasterSignal(PMSIGNAL_RECOVERY_STARTED); 
                bgwriterLaunched = true; 
        }

Please let me know if I miss anything.

Regards,
Hari babu.






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

* Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang
  2012-11-08 18:15 BUG #7643: Issuing a shutdown request while server startup leads to server hang haribabu.kommi@huawei.com
  2012-11-19 19:32 ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Tom Lane <tgl@sss.pgh.pa.us>
  2012-11-20 04:31   ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Hari Babu <haribabu.kommi@huawei.com>
@ 2012-11-20 21:00     ` Tom Lane <tgl@sss.pgh.pa.us>
  2012-11-21 13:32       ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Hari Babu <haribabu.kommi@huawei.com>
  0 siblings, 1 reply; 8+ messages in thread

From: Tom Lane @ 2012-11-20 21:00 UTC (permalink / raw)
  To: Hari Babu <haribabu.kommi@huawei.com>; +Cc: pgsql-bugs

Hari Babu <haribabu.kommi@huawei.com> writes:
>> We're going to need more details about how to reproduce this.

> The problem occurs only when active server is restarting by just adding a
> recovery.conf file to the data directory. 

Well, you can't just put an empty file there, but I eventually managed
to reproduce this with the suggested hack in xlog.c.

I think the key problem is that postmaster.c's sigusr1_handler() is
willing to start new children even after shutdown has been initiated.
I don't see any good reason for it to do that, so I think the
appropriate patch is as attached.

Changing that still leaves us with the postmaster thinking that the
eventual exit(1) of the startup process is a "crash".  This is mostly
cosmetic since it still shuts down okay, but we can fix it by reversing
the order of the first two checks in reaper() --- that is, if Shutdown
is set, we should prefer that code path even if we're in PM_STARTUP
state.

I concluded that it probably wasn't a good idea to have the additional
state transition in SIGINT handling.  Generally PM_STARTUP means "we're
running the startup process and nothing else", and that's useful state
info that we shouldn't throw away lightly.


			regards, tom lane

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

* Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang
  2012-11-08 18:15 BUG #7643: Issuing a shutdown request while server startup leads to server hang haribabu.kommi@huawei.com
  2012-11-19 19:32 ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Tom Lane <tgl@sss.pgh.pa.us>
  2012-11-20 04:31   ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Hari Babu <haribabu.kommi@huawei.com>
  2012-11-20 21:00     ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Tom Lane <tgl@sss.pgh.pa.us>
@ 2012-11-21 13:32       ` Hari Babu <haribabu.kommi@huawei.com>
  2012-11-21 15:59         ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 8+ messages in thread

From: Hari Babu @ 2012-11-21 13:32 UTC (permalink / raw)
  To: 'Tom Lane' <tgl@sss.pgh.pa.us>; +Cc: pgsql-bugs

Tom Lane <tgl@sss.pgh.pa.us > writes:
>I concluded that it probably wasn't a good idea to have the additional
state transition in SIGINT handling.  Generally >PM_STARTUP means "we're
running the startup process and nothing else", and that's useful state info
that we shouldn't >throw away lightly.

I tested the patch, it is working fine.

I have a query regarding the changing of pmState only incase of SIGTERM but
not incase of SIGINT.
Is there any reason to handle like this? or Is it ok to modify the handling
of pmState in SIGTERM same as SIGINT?


Regards,
Hari babu.





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

* Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang
  2012-11-08 18:15 BUG #7643: Issuing a shutdown request while server startup leads to server hang haribabu.kommi@huawei.com
  2012-11-19 19:32 ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Tom Lane <tgl@sss.pgh.pa.us>
  2012-11-20 04:31   ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Hari Babu <haribabu.kommi@huawei.com>
  2012-11-20 21:00     ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Tom Lane <tgl@sss.pgh.pa.us>
  2012-11-21 13:32       ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Hari Babu <haribabu.kommi@huawei.com>
@ 2012-11-21 15:59         ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 8+ messages in thread

From: Tom Lane @ 2012-11-21 15:59 UTC (permalink / raw)
  To: Hari Babu <haribabu.kommi@huawei.com>; +Cc: pgsql-bugs

Hari Babu <haribabu.kommi@huawei.com> writes:
> I have a query regarding the changing of pmState only incase of SIGTERM but
> not incase of SIGINT.
> Is there any reason to handle like this? or Is it ok to modify the handling
> of pmState in SIGTERM same as SIGINT?

AFAICT the "smart shutdown" code path is okay: it transitions to
PM_WAIT_READONLY state, and then PostmasterStateMachine issues SIGTERM
to the startup process and goes to PM_WAIT_BACKENDS state.  Perhaps this
could be done more clearly but I'm disinclined to mess with it.

			regards, tom lane




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

* BUG #7643: Issuing a shutdown request while server startup leads to server hang
@ 2012-11-19 14:28 Hari Babu <haribabu.kommi@huawei.com>
  2012-11-19 18:15 ` Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 1 reply; 8+ messages in thread

From: Hari Babu @ 2012-11-19 14:28 UTC (permalink / raw)
  To: pgsql-bugs

For defect 7643 which is described in the following mail, 
http://archives.postgresql.org/message-id/E1TWWd4-0008AD-9E@wrigleys.postgre
sql.org 
  
The problem identified as the postmaster handling SIGUSR1 after SIGINT
signal leads to the problem as 
bgwriter process is not signaled to terminate by the postmaster as it was
not exist during the processing  of 
SIGINT signal and after that during the processing of SIGUSR1 signal the
process got created. 
  
As the postmaster is waiting for the bgwriter process to terminate in the
further shutdown follow leads the postmaster process to wait until the 
Bgwriter process stops, which enters into a deadlock. 
  
The issue is occurring only incase of SIGINT signal and it was handled for
SIGTERM signal as during the processing of 
SIGTERM signal the pmState is modified which blocks the further start of
bgwriter. 
  
The following patch handles the SIGINT signal also the same way as the
SIGTERM signal for the pmState. 
  
inline patch 1: src/backend/postmaster/postmaster.c (+0/-2 lines) download inline-1.patch*** a/src/backend/postmaster/postmaster.c --- b/src/backend/postmaster/postmaster.c *************** *** 2258,2270 **** pmdie(SIGNAL_ARGS) signal_child(BgWriterPID, SIGTERM); if (WalReceiverPID != 0) signal_child(WalReceiverPID, SIGTERM); ! if (pmState == PM_RECOVERY) { - /* - * Only startup, bgwriter, and
checkpointer should be active - * in this state; we just signaled the first two, and we don't - * want to kill checkpointer yet. - */ pmState = PM_WAIT_BACKENDS; } else if (pmState == PM_RUN || --- 2258,2277 ---- signal_child(BgWriterPID, SIGTERM); if (WalReceiverPID != 0) signal_child(WalReceiverPID, SIGTERM); ! ! /* ! * In the case of pmState as PM_STARTUP, to avoid further startup ! * of bgwriter and checkpointer incase of standby or in archieve ! * recovery mode because we are already in the process of handling ! * fast shutdown. ! * ! * In the case of pmState as PM_RECOVERY, only startup, bgwriter ! * and checkpointer should be active in this state; we just ! * signaled the first two, and we don't want to kill checkpointer ! * yet. ! */ ! if (pmState == PM_RECOVERY || pmState == PM_STARTUP) { pmState = PM_WAIT_BACKENDS; } else if (pmState == PM_RUN || Regards, Hari babu. ^ permalink raw reply [nested|flat] 8+ messages in thread

* Re: BUG #7643: Issuing a shutdown request while server startup leads to server hang
  2012-11-19 14:28 BUG #7643: Issuing a shutdown request while server startup leads to server hang Hari Babu <haribabu.kommi@huawei.com>
@ 2012-11-19 18:15 ` Tom Lane <tgl@sss.pgh.pa.us>
  0 siblings, 0 replies; 8+ messages in thread

From: Tom Lane @ 2012-11-19 18:15 UTC (permalink / raw)
  To: Hari Babu <haribabu.kommi@huawei.com>; +Cc: pgsql-bugs

Hari Babu <haribabu.kommi@huawei.com> writes:
> For defect 7643 which is described in the following mail, 
> http://archives.postgresql.org/message-id/E1TWWd4-0008AD-9E@wrigleys.postgre
> sql.org 
> [ SIGINT handler should treat PM_STARTUP like PM_RECOVERY ]

Yes, I think you're right.  Will fix, thanks for the report and fix!

			regards, tom lane




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


end of thread, other threads:[~2012-11-21 15:59 UTC | newest]

Thread overview: 8+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2012-11-08 18:15 BUG #7643: Issuing a shutdown request while server startup leads to server hang haribabu.kommi@huawei.com
2012-11-19 19:32 ` Tom Lane <tgl@sss.pgh.pa.us>
2012-11-20 04:31   ` Hari Babu <haribabu.kommi@huawei.com>
2012-11-20 21:00     ` Tom Lane <tgl@sss.pgh.pa.us>
2012-11-21 13:32       ` Hari Babu <haribabu.kommi@huawei.com>
2012-11-21 15:59         ` Tom Lane <tgl@sss.pgh.pa.us>
2012-11-19 14:28 BUG #7643: Issuing a shutdown request while server startup leads to server hang Hari Babu <haribabu.kommi@huawei.com>
2012-11-19 18:15 ` Tom Lane <tgl@sss.pgh.pa.us>

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