Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: BUG: Zsh loses history entries since 2015



On Thu, Apr 3, 2025 at 1:56 AM Michael Stapelberg
<stapelberg+zsh@xxxxxxxxxx> wrote:
>
> Yes. During my work day, I open many SSH connections from my laptop
> to my workstation. At the end of the work day, I kill the connection,
> which means all those zsh processes will be killed.

Given this, are you sure it's a SIGINT that's being received?

Typically in cases of a connection shutdown the signal would be
SIGHUP, potentially followed by a SIGKILL if it's a local terminal in
the window/session manager rather than a remote one via SSH.

I'm going to skip some things that Oliver addressed.

> > 2) Change behavior to append current shell history to the file as if
> > APPEND_HISTORY, without attempting to enforce SAVEHIST size or
> > duplicate expiration.  This is probably the option most likely to
>
> This approach would no longer rewrite history when exiting,
> so at which points would zsh rewrite history then?

To clarify, I meant that this behavior would be activated if and only
if the read/write was interrupted (or HUP'd, there's no recourse on
SIGKILL).

I did NOT mean to imply that this would be behavior of "normal" shell,
when NOT interrupted SAVEHIST would apply as it currently does.

> I have not checked what happens when savehistfile() is interrupted,
> but yes, any fix should probably cover both readhistfile() and savehistfile().

On closer look I am reminded that readhistfile() is called from within
savehistfile(), so this should be clarified as specifically "happens
during write-back".

However, I can't think of anything useful to do there ... with
hist-save-by-copy it should (already) just be leaving the ".new" file
behind and (because already dead) skipping the rename over the old
file.  So you probably haven't noticed if/when this happens after the
read is complete.

> > 3) Stop reading, but go on saving internal history per user
> > configuration.  Keeps all the current shell history but would lose
> > part of the existing history file.  Is that what happens now?
>
> I think so.

This is probably wrong (on INT) and not happening (on HUP).

> To be clear: the zsh processes that are killed in my scenario do not
> have any pending history to save

How do you know this?  Because if this could be programmatically
determined at time of exit, the entire history operation could be
optimized away.




Messages sorted by: Reverse Date, Date, Thread, Author