From: Rick Otten <rotten@windfish.net>
To: pgsql-bugs@postgresql.org
Subject: Re: BUG #14287: psql_history gets wiped out
Date: Fri, 12 Aug 2016 11:13:58 -0400
Message-ID: <96ddfae45fe23b4eb77564c0a04f2eeb@www.windfish.net> (raw)
In-Reply-To: <27413.1471013401@sss.pgh.pa.us>
References: <20160811183456.GA656368@alvherre.pgsql>
<15159.1470941747@sss.pgh.pa.us>
<ab5dca6c005692f7bbf5820173b32101@www.windfish.net>
<24679.1470950130@sss.pgh.pa.us>
<fcab184f7c55b63146f3653ccfbe5f0c@www.windfish.net>
<27413.1471013401@sss.pgh.pa.us>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-bugs>
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 <rotten@windfish.net> 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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: rotten@windfish.net
Subject: Re: BUG #14287: psql_history gets wiped out
In-Reply-To: <96ddfae45fe23b4eb77564c0a04f2eeb@www.windfish.net>
References: <20160811183456.GA656368@alvherre.pgsql> <15159.1470941747@sss.pgh.pa.us> <ab5dca6c005692f7bbf5820173b32101@www.windfish.net> <24679.1470950130@sss.pgh.pa.us> <fcab184f7c55b63146f3653ccfbe5f0c@www.windfish.net> <27413.1471013401@sss.pgh.pa.us> <96ddfae45fe23b4eb77564c0a04f2eeb@www.windfish.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
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