<?xml version="1.0" encoding="UTF-8" ?>

<bugzilla version="5.2"
          urlbase="https://bugzilla.altlinux.org/"
          
          maintainer="jenya@basealt.ru"
>

    <bug>
          <bug_id>2013</bug_id>
          
          <creation_ts>2003-01-20 18:54:54 +0300</creation_ts>
          <short_desc>&apos;apt-get install&apos; hangs if installing from 2 or more CDs</short_desc>
          <delta_ts>2004-02-07 19:24:10 +0300</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>4</classification_id>
          <classification>Development</classification>
          <product>Sisyphus</product>
          <component>apt</component>
          <version>unstable</version>
          <rep_platform>all</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>CLOSED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P3</priority>
          <bug_severity>major</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Sergey Vlasov">vsu</reporter>
          <assigned_to name="placeholder@altlinux.org">placeholder</assigned_to>
          <cc>boyarsh</cc>
    
    <cc>glebfm</cc>
    
    <cc>imz</cc>
    
    <cc>ldv</cc>
    
    <cc>placeholder</cc>
    
    <cc>vt</cc>
          
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1837</commentid>
    <comment_count>0</comment_count>
    <who name="Sergey Vlasov">vsu</who>
    <bug_when>2003-01-20 18:54:54 +0300</bug_when>
    <thetext>[&lt;a href=&quot;mailto:root@sirius&quot; target=&quot;_new&quot;&gt;root@sirius&lt;/a&gt; root]# rpm -q apt rpm
apt-0.5.4cnc9-alt4
rpm-4.0.4-alt12

When doing \&amp;quot;apt-get install XXX\&amp;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):

[&lt;a href=&quot;mailto:root@sirius&quot; target=&quot;_new&quot;&gt;root@sirius&lt;/a&gt; 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 \&apos;ALT Linux Master CD 1\&apos; in the drive \&apos;/mnt/cdrom/\&apos; and press enter

Get:1 &lt;a href=&quot;cdrom://ALT&quot;&gt;cdrom://ALT&lt;/a&gt; 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 \&apos;ALT Linux Master CD 3\&apos; in the drive \&apos;/mnt/cdrom/\&apos; and press enter

Get:1 &lt;a href=&quot;cdrom://ALT&quot;&gt;cdrom://ALT&lt;/a&gt; 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:

[&lt;a href=&quot;mailto:root@sirius&quot; target=&quot;_new&quot;&gt;root@sirius&lt;/a&gt; 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
[&lt;a href=&quot;mailto:root@sirius&quot; target=&quot;_new&quot;&gt;root@sirius&lt;/a&gt; root]# strace -v -p 3602
wait4(3609,  &amp;lt;unfinished ...&amp;gt;
[&lt;a href=&quot;mailto:root@sirius&quot; target=&quot;_new&quot;&gt;root@sirius&lt;/a&gt; root]# strace -v -p 3609
fcntl64(3, F_SETLKW, {type=F_WRLCK, whence=SEEK_SET, start=0, len=0} &amp;lt;unfinished ...&amp;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 \&amp;quot;Run it\&amp;quot; comment) is executed several times when multiple CD-ROMs are used. Therefore _system-&amp;gt;Lock() at the end of this loop is executed on each pass other than the last, and _system-&amp;gt;UnLock() before  PM-&amp;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-&amp;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).
---

---

</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4958</commentid>
    <comment_count>1</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2003-01-20 19:26:22 +0300</bug_when>
    <thetext>Maybe set lock right after PM-&amp;gt;DoInstall()?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>8323</commentid>
    <comment_count>2</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2003-01-20 19:26:22 +0300</bug_when>
    <thetext>Maybe set lock right after PM-&amp;gt;DoInstall()?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4959</commentid>
    <comment_count>3</comment_count>
    <who name="Sergey Vlasov">vsu</who>
    <bug_when>2003-01-20 19:40:25 +0300</bug_when>
    <thetext>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...)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>8324</commentid>
    <comment_count>4</comment_count>
    <who name="Sergey Vlasov">vsu</who>
    <bug_when>2003-01-20 19:40:25 +0300</bug_when>
    <thetext>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...)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4960</commentid>
    <comment_count>5</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2003-01-20 19:47:54 +0300</bug_when>
    <thetext>Maybe bring this topic to apt-rpm@ ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>8325</commentid>
    <comment_count>6</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2003-01-20 19:47:54 +0300</bug_when>
    <thetext>Maybe bring this topic to apt-rpm@ ?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>4961</commentid>
    <comment_count>7</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2003-01-21 14:50:38 +0300</bug_when>
    <thetext>Applied this patch in apt-0.5.4cnc9-alt7</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>8326</commentid>
    <comment_count>8</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2003-01-21 14:50:38 +0300</bug_when>
    <thetext>Applied this patch in apt-0.5.4cnc9-alt7</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>11288</commentid>
    <comment_count>9</comment_count>
    <who name="Dmitry V. Levin">ldv</who>
    <bug_when>2004-01-16 21:18:55 +0300</bug_when>
    <thetext>Should be fixed in apt-0.5.4cnc9-alt7 and later. </thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="0"
              isprivate="0"
          >
            <attachid>184</attachid>
            <date>2003-01-20 18:54:54 +0300</date>
            <delta_ts>2003-01-20 18:54:54 +0300</delta_ts>
            <desc>0002013-apt-0.5.4cnc9-alt-lockfix.patch</desc>
            <filename>0002013-apt-0.5.4cnc9-alt-lockfix.patch</filename>
            <type>application/octet-stream</type>
            <size>490</size>
            <attacher name="Sergey Vlasov">vsu</attacher>
            
              <data encoding="base64">LS0tIGFwdC0wLjUuNGNuYzkvY21kbGluZS9hcHQtZ2V0LmNjLmFsdC1sb2NrZml4CVN1biBKYW4g
MTkgMTg6NTk6NDggMjAwMworKysgYXB0LTAuNS40Y25jOS9jbWRsaW5lL2FwdC1nZXQuY2MJU3Vu
IEphbiAxOSAxOTo1OTo1NyAyMDAzCkBAIC05NjYsMTQgKzk2NiwxNCBAQAogCSAgICAgICByZXQg
PSBEb0F1dG9DbGVhbigqQ21kTCk7CiAJICAgIHJldHVybiByZXQ7CiAJIH0KKworCSBfc3lzdGVt
LT5Mb2NrKCk7CiAgICAgICB9CiAgICAgICAKICAgICAgIC8vIFJlbG9hZCB0aGUgZmV0Y2hlciBv
YmplY3QgYW5kIGxvb3AgYWdhaW4gZm9yIG1lZGlhIHN3YXBwaW5nCiAgICAgICBGZXRjaGVyLlNo
dXRkb3duKCk7CiAgICAgICBpZiAoUE0tPkdldEFyY2hpdmVzKCZGZXRjaGVyLCZMaXN0LCZSZWNz
KSA9PSBmYWxzZSkKIAkgcmV0dXJuIGZhbHNlOwotICAgICAgCi0gICAgICBfc3lzdGVtLT5Mb2Nr
KCk7CiAgICB9ICAgCiB9CiAJCQkJCQkJCQkvKn19fSovCg==
</data>

          </attachment>
      

    </bug>

</bugzilla>