Race condition when writing ~/.bash_history

Bug #10809 reported by Debian Bug Importer
10
Affects Status Importance Assigned to Milestone
bash (Debian)
Confirmed
Unknown
bash (Ubuntu)
Invalid
Medium
Matthias Klose

Bug Description

Automatically imported from Debian bug report #283702 http://bugs.debian.org/283702

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Automatically imported from Debian bug report #283702 http://bugs.debian.org/283702

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Message-Id: <email address hidden>
Date: Tue, 30 Nov 2004 21:25:46 +0300
From: Cyril Bouthors <email address hidden>
To: Debian Bug Tracking System <email address hidden>
Subject: Race condition when writing ~/.bash_history

Package: bash
Version: 3.0-10
Severity: critical
Justification: causes serious data loss

Hi,

About once a month, my ~/.bash_history gets empty. This is quite
annoying because I'm using C-r really often.

I get the same problem again and again for quite some time now, maybe
two years.

I think it comes from the fact that I'm not using a typical setup.
I'm running 5 different "bash --noediting -i" under Emacs with
shell-mode buffers and I'm often exiting Emacs without closing all the
shells by hand. The 5 bash processes get killed and I guess they try
to write ~/.bash_history at the exact same time.

I think it's a basic race condition, bash should lock the file before
trying to write it but I haven't checked if it does.

I haven't reproduced the exact same bug where ~/.bash_history gets
empty but a similar unwanted behaviour can be reproduced by doing
massive parallel "history -w" with:

cyb@wide:~$ export HISTFILE=/tmp/history
cyb@wide:~$ export HISTSIZE=100000
cyb@wide:~$ rm -f $HISTFILE
cyb@wide:~$ for a in `seq 5`; do xterm -e 'for a in `seq 1000`; do echo "echo $a; history -w"; done | bash -i' ; done
cyb@wide:~$ wc -l $HISTFILE
10000 /tmp/history
cyb@wide:~$ rm $HISTFILE
cyb@wide:~$ for a in `seq 5`; do xterm -e 'for a in `seq 1000`; do echo "echo $a; history -w"; done | bash -i' & done
[1] 4715
[2] 4721
[3] 4722
[4] 4723
[5] 4724
cyb@wide:~$ wait
[1] Done xterm -e 'for a in `seq 1000`; do echo "echo $a; history -w"; done | bash -i'
[2] Done xterm -e 'for a in `seq 1000`; do echo "echo $a; history -w"; done | bash -i'
[4]- Done xterm -e 'for a in `seq 1000`; do echo "echo $a; history -w"; done | bash -i'
[5]+ Done xterm -e 'for a in `seq 1000`; do echo "echo $a; history -w"; done | bash -i'
[3]+ Done xterm -e 'for a in `seq 1000`; do echo "echo $a; history -w"; done | bash -i'
cyb@wide:~$ wc -l $HISTFILE
2794 /tmp/history
cyb@wide:~$ unset HISTFILE
cyb@wide:~$

/tmp/history should be 10k lines long in both cases (5*1000*2).

Regards

-- System Information:
Debian Release: 3.1
  APT prefers unstable
  APT policy: (500, 'unstable')
Architecture: i386 (i686)
Kernel: Linux 2.6.9-1-686
Locale: LANG=C, LC_CTYPE=C (charmap=ANSI_X3.4-1968)

Versions of packages bash depends on:
ii base-files 3.1.0 Debian base system miscellaneous f
ii libc6 2.3.2.ds1-18 GNU C Library: Shared libraries an
ii libncurses5 5.4-4 Shared libraries for terminal hand
ii passwd 1:4.0.3-30.4 Change and administer password and

-- no debconf information

Revision history for this message
In , Peter Walser (peterwalser) wrote : bash-history not thread save?

As far as I understand uses bash/history the function readline.

with bash 2.05b.0 :
[... steps described above ...]
$ wc -l $HISTFILE
2805 /tmp/history

So I get quite the same behavior.

I think readline/history is not thread save, but it's not critical.

Regards

Peter

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Message-Id: <email address hidden>
Date: Wed, 1 Dec 2004 16:52:11 +0100
From: Peter Walser <email address hidden>
To: <email address hidden>
Subject: bash-history not thread save?

As far as I understand uses bash/history the function readline.

with bash 2.05b.0 :
[... steps described above ...]
$ wc -l $HISTFILE
2805 /tmp/history

So I get quite the same behavior.

I think readline/history is not thread save, but it's not critical.

Regards

Peter

Revision history for this message
In , Matthias Klose (doko-cs) wrote : Re: Bug#283702: bash-history not thread save?

severity 283702 important
thanks

Peter Walser writes:
>
> As far as I understand uses bash/history the function readline.
>
> with bash 2.05b.0 :
> [... steps described above ...]
> $ wc -l $HISTFILE
> 2805 /tmp/history
>
> So I get quite the same behavior.
>
> I think readline/history is not thread save, but it's not critical.

agreed.

Revision history for this message
Matthias Klose (doko) wrote :

acknowledged, although not RC.

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Message-ID: <email address hidden>
Date: Thu, 2 Dec 2004 00:18:54 +0100
From: Matthias Klose <email address hidden>
To: <email address hidden>
Cc: Peter Walser <email address hidden>
Subject: Re: Bug#283702: bash-history not thread save?

severity 283702 important
thanks

Peter Walser writes:
>
> As far as I understand uses bash/history the function readline.
>
> with bash 2.05b.0 :
> [... steps described above ...]
> $ wc -l $HISTFILE
> 2805 /tmp/history
>
> So I get quite the same behavior.
>
> I think readline/history is not thread save, but it's not critical.

agreed.

Revision history for this message
In , Cyril Bouthors (cyril) wrote : Forward to upstream?

This is a bug in upstream, maybe we should forward this to upstream
authors, they'll probably have a good reactivity.
--
Cyril Bouthors

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Message-ID: <email address hidden>
Date: Thu, 09 Dec 2004 19:17:38 +0300
From: Cyril Bouthors <email address hidden>
To: <email address hidden>
Subject: Forward to upstream?

--=-=-=

This is a bug in upstream, maybe we should forward this to upstream
authors, they'll probably have a good reactivity.
--
Cyril Bouthors

--=-=-=
Content-Type: application/pgp-signature

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.5 (GNU/Linux)

iD8DBQBBuHqiZ1SJHeqsYt8RAkYmAJ0duXAETm8sCoX4NpxUdxPEgIy69ACfdgB8
8AouwFS84rHVomqwbbn5uJk=
=/DAi
-----END PGP SIGNATURE-----
--=-=-=--

Revision history for this message
In , Chet Ramey (chet-ramey) wrote : Re: Bug#283702: Race condition when writing ~/.bash_history (forwarded from Cyril Bouthors)

Matthias Klose wrote:
> [severity was lowerd in the Debian BTS]

I'm not inclined to do anything about this.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
      Live Strong.
Chet Ramey, ITS, CWRU <email address hidden> http://cnswww.cns.cwru.edu/~chet/

Revision history for this message
In , Matthias Klose (doko-cs) wrote :

severity 283702 minor
tags 283702 + wontfix
forwarded 283702 <email address hidden>
thanks

Chet Ramey writes:
>
> I'm not inclined to do anything about this.
>
> Chet
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> ( ``Discere est Dolere'' -- chet )
> Live Strong.
> Chet Ramey, ITS, CWRU <email address hidden> http://cnswww.cns.cwru.edu/~chet/

Revision history for this message
In , Matthias Klose (doko-cs) wrote : bash reports

retitle 316407 [fixed in 3.1] "cd -P" hangs bash on some configurations
forwarded 283702 <email address hidden>
tags 283702 + upstream

forwarded 288319 <email address hidden>
tags 288319 + upstream

forwarded 310598 <email address hidden>
tags 310598 + upstream

retitle 310308 [fixed in 3.1] bash: bash closes fd 2 after an unsuccessful exec
tags 310308 + upstream
tags 310308 + fixed-upstream

tags 313538 + pending

retitle 238226 [fixed in 3.1] bash: segfaults on ia64 when expanding large glob
tags 238226 + upstream
tags 238226 + fixed-upstream

retitle 309654 [fixed in 3.1] Trouble editing with multibyte chars
tags 309654 + upstream
tags 309654 + fixed-upstream

retitle 317324 [fixed in 3.1] bash: double free
tags 317324 + upstream
tags 317324 + fixed-upstream

retitle 310308 [fixed in 3.1] bash closes fd 2 after an unsuccessful exec
tags 310308 + upstream
tags 310308 + fixed-upstream

retitle 297330 [fixed in 3.1] bash3: <Esc>-/ garbages colored prompt in vi-mode
tags 297330 + upstream
tags 297330 + fixed-upstream

retitle 316206 [fixed in 3.1] bash segfaults if execve'd with NULL argv
tags 316206 + upstream
tags 316206 + fixed-upstream

retitle 327035 [fixed in 3.1] bash: manpage macro problem?
tags 327035 + upstream
tags 327035 + fixed-upstream

forwarded 292751 <email address hidden>
tags 292751 + upstream

forwarded 294078 <email address hidden>
tags 294078 + upstream

forwarded 296099 <email address hidden>
tags 296099 + upstream

forwarded 298889 <email address hidden>
tags 298889 + upstream

forwarded #303113 <email address hidden>
tags #303113 + upstream

forwarded 305485 <email address hidden>
tags 305485 + upstream

forwarded 327414 <email address hidden>
tags 327414 + upstream

forwarded 314363 <email address hidden>
tags 314363 + upstream

forwarded 327274 <email address hidden>
tags 327274 + upstream

forwarded 293096 <email address hidden>
tags 293096 + upstream

thanks

Revision history for this message
Matthias Klose (doko) wrote :

> I'm not inclined to do anything about this.
>
> Chet

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Message-ID: <email address hidden>
Date: Fri, 09 Sep 2005 20:55:40 -0400
From: Chet Ramey <email address hidden>
To: Cyril Bouthors <email address hidden>, <email address hidden>
Subject: Re: Bug#283702: Race condition when writing ~/.bash_history (forwarded from Cyril Bouthors)

Matthias Klose wrote:
> [severity was lowerd in the Debian BTS]

I'm not inclined to do anything about this.

Chet
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
( ``Discere est Dolere'' -- chet )
      Live Strong.
Chet Ramey, ITS, CWRU <email address hidden> http://cnswww.cns.cwru.edu/~chet/

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Message-ID: <email address hidden>
Date: Sat, 10 Sep 2005 08:04:19 +0200
From: Matthias Klose <email address hidden>
To: <email address hidden>
Subject: Re: Bug#283702: Race condition when writing ~/.bash_history (forwarded from Cyril Bouthors)

severity 283702 minor
tags 283702 + wontfix
forwarded 283702 <email address hidden>
thanks

Chet Ramey writes:
>
> I'm not inclined to do anything about this.
>
> Chet
> --
> ``The lyf so short, the craft so long to lerne.'' - Chaucer
> ( ``Discere est Dolere'' -- chet )
> Live Strong.
> Chet Ramey, ITS, CWRU <email address hidden> http://cnswww.cns.cwru.edu/~chet/

Revision history for this message
Debian Bug Importer (debzilla) wrote :

Message-ID: <email address hidden>
Date: Sat, 10 Sep 2005 14:30:24 +0200
From: Matthias Klose <email address hidden>
To: <email address hidden>
Subject: bash reports

retitle 316407 [fixed in 3.1] "cd -P" hangs bash on some configurations
forwarded 283702 <email address hidden>
tags 283702 + upstream

forwarded 288319 <email address hidden>
tags 288319 + upstream

forwarded 310598 <email address hidden>
tags 310598 + upstream

retitle 310308 [fixed in 3.1] bash: bash closes fd 2 after an unsuccessful exec
tags 310308 + upstream
tags 310308 + fixed-upstream

tags 313538 + pending

retitle 238226 [fixed in 3.1] bash: segfaults on ia64 when expanding large glob
tags 238226 + upstream
tags 238226 + fixed-upstream

retitle 309654 [fixed in 3.1] Trouble editing with multibyte chars
tags 309654 + upstream
tags 309654 + fixed-upstream

retitle 317324 [fixed in 3.1] bash: double free
tags 317324 + upstream
tags 317324 + fixed-upstream

retitle 310308 [fixed in 3.1] bash closes fd 2 after an unsuccessful exec
tags 310308 + upstream
tags 310308 + fixed-upstream

retitle 297330 [fixed in 3.1] bash3: <Esc>-/ garbages colored prompt in vi-mode
tags 297330 + upstream
tags 297330 + fixed-upstream

retitle 316206 [fixed in 3.1] bash segfaults if execve'd with NULL argv
tags 316206 + upstream
tags 316206 + fixed-upstream

retitle 327035 [fixed in 3.1] bash: manpage macro problem?
tags 327035 + upstream
tags 327035 + fixed-upstream

forwarded 292751 <email address hidden>
tags 292751 + upstream

forwarded 294078 <email address hidden>
tags 294078 + upstream

forwarded 296099 <email address hidden>
tags 296099 + upstream

forwarded 298889 <email address hidden>
tags 298889 + upstream

forwarded #303113 <email address hidden>
tags #303113 + upstream

forwarded 305485 <email address hidden>
tags 305485 + upstream

forwarded 327414 <email address hidden>
tags 327414 + upstream

forwarded 314363 <email address hidden>
tags 314363 + upstream

forwarded 327274 <email address hidden>
tags 327274 + upstream

forwarded 293096 <email address hidden>
tags 293096 + upstream

thanks

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.