Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1bYEAV-0006P3-7I for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Aug 2016 15:14:43 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84_2) (envelope-from ) id 1bYEAU-0007I4-Pz for pgsql-bugs@arkaria.postgresql.org; Fri, 12 Aug 2016 15:14:42 +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 1bYE9q-0006Ym-2Y for pgsql-bugs@postgresql.org; Fri, 12 Aug 2016 15:14:02 +0000 Received: from mail.windfish.net ([23.253.200.25]) by makus.postgresql.org with esmtps (TLS1.1:ECDHE_RSA_AES_256_CBC_SHA1:256) (Exim 4.84_2) (envelope-from ) id 1bYE9n-0003sv-FG for pgsql-bugs@postgresql.org; Fri, 12 Aug 2016 15:14:00 +0000 Received: by mail.windfish.net (Postfix, from userid 33) id 8FBAF765C4; Fri, 12 Aug 2016 11:13:58 -0400 (EDT) To: pgsql-bugs@postgresql.org Subject: Re: BUG #14287: =?UTF-8?Q?psql=5Fhistory=20gets=20wiped=20?= =?UTF-8?Q?out?= X-PHP-Originating-Script: 33:rcube.php MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="=_f470d17ce2f6f2fe3f300fa01b4ec155" Date: Fri, 12 Aug 2016 11:13:58 -0400 From: Rick Otten In-Reply-To: <27413.1471013401@sss.pgh.pa.us> References: <20160811183456.GA656368@alvherre.pgsql> <15159.1470941747@sss.pgh.pa.us> <24679.1470950130@sss.pgh.pa.us> <27413.1471013401@sss.pgh.pa.us> Message-ID: <96ddfae45fe23b4eb77564c0a04f2eeb@www.windfish.net> X-Sender: rotten@windfish.net User-Agent: Roundcube Webmail/1.0.3 X-Pg-Spam-Score: -2.4 (--) 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 --=_f470d17ce2f6f2fe3f300fa01b4ec155 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset=US-ASCII Wouldn't it be better to write the commands to the history file as you go instead of at the end of the session? At most you would only need to close the file pointer when you tear down instead of having to flush the command history (which may be hundreds of queries). On 2016-08-12 10:50, Tom Lane wrote: > Rick Otten writes: > >> And here is what the last few lines of the strace look like when I close the (ssh terminal) window: > >> --- SIGHUP {si_signo=SIGHUP, si_code=SI_USER, si_pid=95075, si_uid=5432} --- +++ killed by SIGHUP +++ > > So the issue seems to be that psql is getting killed by SIGHUP before > it can write the history file (in this example), or in the midst of > writing the history file (in your problem cases), depending on timing. > > The weird thing here is that psql is able to see EOF on stdin and > begin taking actions in response to that before SIGHUP arrives. > I'm not sure if that's expected or not. That seems like a deliberately > created race condition, which is seldom a good idea. > > Anyway it seems like your behavioral change must boil down to a timing > change in either the kernel or sshd. There's nothing in psql that changed > in this area, and probably not in libedit either. > > We could maybe try to prevent this by blocking signals while writing the > history file, but I'm not exactly convinced that would be a good idea. > It's probably be better to pester kernel & sshd people about whether > they changed anything here. > > regards, tom lane --=_f470d17ce2f6f2fe3f300fa01b4ec155 Content-Transfer-Encoding: quoted-printable Content-Type: text/html; charset=UTF-8

Wouldn't it be better to write the commands to the history file as you g= o instead of at the end of the session?

At most you would only need to close the file pointer when you tear down= instead of having to flush the command history (which may be hundreds of q= ueries).

 

On 2016-08-12 10:50, Tom Lane wrote:

Rick Otten <rotten@windfish=
=2Enet> writes:
And here is what the last few lines of the strace= look like when I close the (ssh terminal) window:
--- SIGHUP {si_signo=3DSIGHUP, si_code=3DSI_USER,= si_pid=3D95075, si_uid=3D5432} --- +++ killed by SIGHUP +++
So the issue seems to be that psql is getting killed by SIGHUP before
it can write the history file (in this example), or in the midst of
writing the history file (in your problem cases), depending on timing.

The weird thing here is that psql is able to see EOF on stdin and
begin taking actions in response to that before SIGHUP arrives.
I'm not sure if that's expected or not.  That seems like a deliberately
created race condition, which is seldom a good idea.

Anyway it seems like your behavioral change must boil down to a timing
change in either the kernel or sshd.  There's nothing in psql that changed
in this area, and probably not in libedit either.

We could maybe try to prevent this by blocking signals while writing the
history file, but I'm not exactly convinced that would be a good idea.
It's probably be better to pester kernel & sshd people about whether
they changed anything here.

			regards, tom lane

 

--=_f470d17ce2f6f2fe3f300fa01b4ec155--