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).
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
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: ANSI_X3. 4-1968)
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=
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