Bug 2013 - 'apt-get install' hangs if installing from 2 or more CDs
: 'apt-get install' hangs if installing from 2 or more CDs
Status: CLOSED FIXED
: Sisyphus
(All bugs in Sisyphus/apt)
: unstable
: all Linux
: P3 major
Assigned To:
:
:
:
:
:
  Show dependency tree
 
Reported: 2003-01-20 18:54 by
Modified: 2004-02-07 19:24 (History)


Attachments
0002013-apt-0.5.4cnc9-alt-lockfix.patch (490 bytes, application/octet-stream)
2003-01-20 18:54, Sergey Vlasov
no flags Details


Note

You need to log in before you can comment on or make changes to this bug.


Description From 2003-01-20 18:54:54
[<a href="mailto:root@sirius" target="_new">root@sirius</a> root]# rpm -q apt
rpm
apt-0.5.4cnc9-alt4
rpm-4.0.4-alt12

When doing \&quot;apt-get install XXX\&quot; and the required packages are on
more than one CD-ROM (so disk changing is necessary), the operation hangs after
fetching all packages.  I have reproduced this on my system (which is only
partially upgraded from Sisyphus, and some packages are from Master 2.0 CDs):

[<a href="mailto:root@sirius" target="_new">root@sirius</a> root]# apt-get
install libpwlib-devel
Reading Package Lists... Done
Building Dependency Tree... Done
The following extra packages will be installed:
  libpwlib 
The following NEW packages will be installed:
  libpwlib libpwlib-devel 
0 packages upgraded, 2 newly installed, 0 removed and 0 not upgraded.
Need to get 0B/1312kB of archives. After unpacking 4459kB will be used.
Do you want to continue? [Y/n] 
Media Change: Please insert the disc labeled \'ALT Linux Master CD 1\' in the
drive \'/mnt/cdrom/\' and press enter

Get:1 <a href="cdrom://ALT">cdrom://ALT</a> Linux Master CD 1 Mandrake/Master
libpwlib 1.2.12-alt1 [918kB]
Fetched 918kB in 16s (54.1kB/s)
Media Change: Please insert the disc labeled \'ALT Linux Master CD 3\' in the
drive \'/mnt/cdrom/\' and press enter

Get:1 <a href="cdrom://ALT">cdrom://ALT</a> Linux Master CD 3 Mandrake/Master
libpwlib-devel 1.2.12-alt1 [394kB]
Fetched 394kB in 25s (15.3kB/s)
Executing RPM (/bin/rpm -Uvh --fancypercent --oldpackage)...

At this point the process hangs until killed by ^C.  Further examination from
another terminal gives:

[<a href="mailto:root@sirius" target="_new">root@sirius</a> root]# lsof
/var/lib/rpm/Packages 
COMMAND  PID USER   FD   TYPE DEVICE     SIZE NODE NAME
apt-get 3602 root    4uW  REG   3,11 15044608  112 /var/lib/rpm/Packages
rpm     3609 root    3u   REG   3,11 15044608  112 /var/lib/rpm/Packages
[<a href="mailto:root@sirius" target="_new">root@sirius</a> root]# strace -v -p
3602
wait4(3609,  &lt;unfinished ...&gt;
[<a href="mailto:root@sirius" target="_new">root@sirius</a> root]# strace -v -p
3609
fcntl64(3, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0}
&lt;unfinished ...&gt;

This shows that rpm is waiting for the database lock, but apt-get did not
release it before running rpm, therefore a deadlock happens.

The problem appears only when the packages are fetched from CD-ROM, and more
than one CD-ROM disk is used (installation from local files, FTP, or from
CD-ROM when only one disk is needed work without this happening).  Repeating
the failed apt-get command after killing the hung one with ^C also works
(because this time all package files are in the cache).

I have tracked down the problem to a bug in the apt-get code
(apt-0.5.4cnc9/cmdline/apt-get.cc, InstallPackages()).  The problem is that the
body of the loop at the end of this function (with the \&quot;Run it\&quot;
comment) is executed several times when multiple CD-ROMs are used. Therefore
_system-&gt;Lock() at the end of this loop is executed on each pass other than
the last, and _system-&gt;UnLock() before  PM-&gt;DoInstall() does not really
unlock the database, because the lock count remains greater than zero.

I suggest to move this Lock() call earlier, so that it is called only when
UnLock() was called before.  The difference will be that Fetcher.Shutdown() and
PM-&gt;GetArchives() will now be called with the lock held, but these
operations should work irrespective of the lock state.

The patch is attached (tested with apt-0.5.4cnc9-alt4; -alt6 does not seem to
have any changes in the related code - did not test it actually).
---

---
------- Comment #1 From 2003-01-20 19:26:22 -------
Maybe set lock right after PM-&gt;DoInstall()?
------- Comment #2 From 2003-01-20 19:26:22 -------
Maybe set lock right after PM-&gt;DoInstall()?
------- Comment #3 From 2003-01-20 19:40:25 -------
Maybe - I did not try this (something might depend on the fact that rpmdb is
unlocked on the successfull return from InstallPackages().

(apt-get code is not very pretty - e.g., look what they do with CmdL nearby...)
------- Comment #4 From 2003-01-20 19:40:25 -------
Maybe - I did not try this (something might depend on the fact that rpmdb is
unlocked on the successfull return from InstallPackages().

(apt-get code is not very pretty - e.g., look what they do with CmdL nearby...)
------- Comment #5 From 2003-01-20 19:47:54 -------
Maybe bring this topic to apt-rpm@ ?
------- Comment #6 From 2003-01-20 19:47:54 -------
Maybe bring this topic to apt-rpm@ ?
------- Comment #7 From 2003-01-21 14:50:38 -------
Applied this patch in apt-0.5.4cnc9-alt7
------- Comment #8 From 2003-01-21 14:50:38 -------
Applied this patch in apt-0.5.4cnc9-alt7
------- Comment #9 From 2004-01-16 21:18:55 -------
Should be fixed in apt-0.5.4cnc9-alt7 and later.