Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1dt6hR-0003rn-H6 for pgsql-bugs@arkaria.postgresql.org; Sat, 16 Sep 2017 06:35:33 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1dszYG-0001Ni-LA for pgsql-bugs@arkaria.postgresql.org; Fri, 15 Sep 2017 22:57:36 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dszYF-0001NB-Uf for pgsql-bugs@postgresql.org; Fri, 15 Sep 2017 22:57:36 +0000 Received: from placid1.grammatech.com ([98.159.213.246] helo=placid.grammatech.com) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1dszYD-0000XZ-1x for pgsql-bugs@postgresql.org; Fri, 15 Sep 2017 22:57:34 +0000 Received: from placid.grammatech.com (placid1 [192.168.219.7]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by placid.grammatech.com (Postfix) with ESMTPS id CADD5B242C; Fri, 15 Sep 2017 18:57:30 -0400 (EDT) Received: from [10.233.219.191] (barracuda.grammatech.com [192.168.219.10]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by placid.grammatech.com (Postfix) with ESMTPSA id BCF83B20A5; Fri, 15 Sep 2017 18:57:30 -0400 (EDT) Subject: Re: PANIC during exit on behalf of FATAL semop error To: Andres Freund Cc: "pgsql-bugs@postgresql.org" References: <075f128e-5e1b-694c-c947-d48cc56e4123@grammatech.com> <20170915214219.qijlxmzjxuhdheic@alap3.anarazel.de> From: Dave Vitek Message-ID: <65a8f998-c284-eda7-bfea-9e4e1786613a@grammatech.com> Date: Fri, 15 Sep 2017 18:57:30 -0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:52.0) Gecko/20100101 Thunderbird/52.3.0 MIME-Version: 1.0 In-Reply-To: <20170915214219.qijlxmzjxuhdheic@alap3.anarazel.de> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-US List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org On 9/15/2017 5:42 PM, Andres Freund wrote: > Hi, > > On 2017-09-15 17:30:51 -0400, Dave Vitek wrote: >> We have an x86_64 linux machine running postgresql 9.6.2.  Our application >> uses LISTEN/NOTIFY.  We recently made a change so that our testing >> infrastructure would notice postgres crashes and out popped this crash: > Oh. That's curious. > >> elog(PANIC, "queueing for lock while waiting on another one"); >> >> in this code: >> >> /* >>  * Add ourselves to the end of the queue. >>  * >>  * NB: Mode can be LW_WAIT_UNTIL_FREE here! >>  */ >> static void >> LWLockQueueSelf(LWLock *lock, LWLockMode mode) >> { >>         /* >>          * If we don't have a PGPROC structure, there's no way to wait. This >>          * should never occur, since MyProc should only be null during >> shared >>          * memory initialization. >>          */ >>         if (MyProc == NULL) >>                 elog(PANIC, "cannot wait without a PGPROC structure"); >> >>         if (MyProc->lwWaiting) >> ----->       elog(PANIC, "queueing for lock while waiting on another one"); >> <------------------- >> Here's a stack trace and a more verbose stack trace. >> >> #0 0x00007ff27bb50c37 in __GI_raise (sig=sig@entry=6) at ../nptl/sysdeps/unix/sysv/linux/raise.c:56 >> #1 0x00007ff27bb54028 in __GI_abort () at abort.c:89 >> #2 0x0000000000978119 in errfinish (dummy=0) at elog.c:557 >> #3 0x000000000097a671 in elog_finish (elevel=22, fmt=0xc5a000 "queueing for lock while waiting on another one") at elog.c:1378 >> #4 0x000000000080eb73 in LWLockQueueSelf (lock=0x7ff272b06480, mode=LW_EXCLUSIVE) at lwlock.c:1035 >> #5 0x000000000080ee30 in LWLockAcquire (lock=0x7ff272b06480, mode=LW_EXCLUSIVE) at lwlock.c:1250 >> #6 0x00000000007fe416 in CleanupInvalidationState (status=1, arg=140679430974720) at sinvaladt.c:344 >> #7 0x00000000007f5132 in shmem_exit (code=1) at ipc.c:261 >> #8 0x00000000007f4f63 in proc_exit_prepare (code=1) at ipc.c:185 >> #9 0x00000000007f4eb3 in proc_exit (code=1) at ipc.c:102 >> #10 0x00000000009780e7 in errfinish (dummy=0) at elog.c:543 >> #11 0x000000000097a671 in elog_finish (elevel=21, fmt=0xc45b4a "semop(id=%d) failed: %m") at elog.c:1378 >> #12 0x00000000007881d9 in PGSemaphoreLock (sema=0x7ff27b7d6740) at pg_sema.c:391 >> #13 0x000000000080ee74 in LWLockAcquire (lock=0x7ff272b06f00, mode=LW_SHARED) at lwlock.c:1287 >> #14 0x0000000000604177 in asyncQueueReadAllNotifications () at async.c:1877 >> #15 0x000000000060464c in ProcessIncomingNotify () at async.c:2058 >> #16 0x0000000000603f04 in ProcessNotifyInterrupt () at async.c:1732 >> #17 0x000000000081da4d in ProcessClientReadInterrupt (blocked=1 '\001') at postgres.c:537 >> #18 0x00000000006d7a8d in secure_read (port=0x2bb90b0, ptr=0xfe8da0 , len=8192) at be-secure.c:177 >> #19 0x00000000006e3f82 in pq_recvbuf () at pqcomm.c:921 >> #20 0x00000000006e4022 in pq_getbyte () at pqcomm.c:964 >> #21 0x000000000081d495 in SocketBackend (inBuf=0x7ffe148694a0) at postgres.c:334 >> #22 0x000000000081d9db in ReadCommand (inBuf=0x7ffe148694a0) at postgres.c:507 >> #23 0x00000000008228ff in PostgresMain (argc=1, argv=0x2bbb308, dbname=0x2bbb2f0 "cshub", username=0x2bbb2d0 "cshubuser") at postgres.c:4021 >> #24 0x000000000079f903 in BackendRun (port=0x2bb90b0) at postmaster.c:4272 >> #25 0x000000000079ef9d in BackendStartup (port=0x2bb90b0) at postmaster.c:3946 >> #26 0x000000000079b645 in ServerLoop () at postmaster.c:1701 >> #27 0x000000000079ab97 in PostmasterMain (argc=3, argv=0x2b918b0) at postmaster.c:1309 >> #28 0x00000000006e8f8c in main (argc=3, argv=0x2b918b0) at main.c:228 >> >> >> So the PANIC is really happening because of the first problem: >> >> /* >>  * PGSemaphoreLock >>  * >>  * Lock a semaphore (decrement count), blocking if count would be < 0 >>  */ >> void >> PGSemaphoreLock(PGSemaphore sema) >> { >>         if (errStatus < 0) >> ------>     elog(FATAL, "semop(id=%d) failed: %m", sema->semId); >> <-------------- >> } >> >> Should this one use PANIC instead of FATAL given that the FATAL exit path >> causes a PANIC in some cases?  Is there an opportunity to repair the state >> of things enough that a FATAL exit is possible here? > I'm right now more curious to discover how this happened. Are you by any > chance running this with systemd/logind in the mix? It's RemoveIPC= > setting can cause such things... > > Greetings, > > Andres Freund Thanks for the quick reply. I can see a systemd-logind process running on the machine.  It's using Ubuntu "trusty."  I did not set it up, but assume it might be largely using default settings. The logind.conf looks like: [Login] #NAutoVTs=6 #ReserveVT=6 #KillUserProcesses=no #KillOnlyUsers= #KillExcludeUsers=root Controllers=blkio cpu cpuacct cpuset devices freezer hugetlb memory perf_event net_cls net_prio ResetControllers= #InhibitDelayMaxSec=5 #HandlePowerKey=poweroff #HandleSuspendKey=suspend #HandleHibernateKey=hibernate #HandleLidSwitch=suspend #PowerKeyIgnoreInhibited=no #SuspendKeyIgnoreInhibited=no #HibernateKeyIgnoreInhibited=no #LidSwitchIgnoreInhibited=yes #IdleAction=ignore #IdleActionSec=30min so no mention of RemoveIPC.  I will add the line to disable it and reboot the system anyway.  I wonder how it complains about unrecognized variables? It's also not completely impossible that a human trying to fix something ran ipcrm in error. - Dave -- Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs