Broken timedate handling for failed hook runs

Bug #986183 reported by Loïc Minier
10
This bug affects 1 person
Affects Status Importance Assigned to Milestone
update-notifier (Ubuntu)
Fix Released
Medium
Steve Langasek
Precise
Fix Released
Medium
Steve Langasek
Quantal
Fix Released
Medium
Steve Langasek

Bug Description

[Test Case]
1. As root, run:
cat > /usr/share/package-data-downloads/test-failure
Url: http://doesnotexist.example.com/
Sha256: b732d5a4f4b122efb676d7bcb564fad58b0ca0bb22d9da18089d847c17533537

Script: /bin/true
^D
2. Run 'sudo /usr/lib/update-notifier/package-data-downloader'
3. Confirm that the file /var/lib/update-notifier/package-data-downloads/test-failure.failed has been created.
4. Run 'sudo date -d "now + 4 days" to set the clock in the future
5. Run 'sudo /usr/lib/update-notifier/package-data-downloader' again
6. Confirm that /var/lib/update-notifier/package-data-downloads/test-failure.failed still exists, and has not been replaced with /var/lib/update-notifier/package-data-downloads/test-failure.permanent-failure
7. Install the update-notifier-common package from precise-proposed
8. Repeat steps 4 and 5
9. Confirm that /var/lib/update-notifier/package-data-downloads/test-failure.permanent-failure now exists, and /var/lib/update-notifier/package-data-downloads/test-failure.failed no longer exists.
10. run 'sudo service ntp stop; sudo ntpdate 0.ubuntu.pool.ntp.org; sudo service ntp start' to set your clock back to the correct time, and 'sudo rm /usr/share/package-data-downloads/test-failure /var/lib/update-notifier/package-data-downloads/test-failure*' to clean up the test files.

Hi,

After some recent updates in precise, I've started receiving cron emails such as:

Date: Tue, 17 Apr 2012 11:49:02 +0200 (CEST)
Subject: Anacron job 'cron.daily' on bee

/etc/cron.daily/update-notifier-common:
flashplugin-installer: downloading
http://archive.canonical.com/pool/partner/a/adobe-flashplugin/adobe-flashplugin_
11.2.202.228.orig.tar.gz
Installing from local file /tmp/tmppRl5Rq.gz
Flash Plugin installed.

Then the next day:
Date: Wed, 18 Apr 2012 11:25:36 +0200 (CEST)
Subject: Anacron job 'cron.daily' on bee

/etc/cron.daily/update-notifier-common:
flashplugin-installer: downloading
http://archive.canonical.com/pool/partner/a/adobe-flashplugin/adobe-flashplugin_
11.2.202.228.orig.tar.gz
Installing from local file /tmp/tmpTeTtwA.gz
Flash Plugin installed.

Then after a day of silence:
Date: Fri, 20 Apr 2012 07:38:09 +0200 (CEST)
Subject: Anacron job 'cron.daily' on bee

/etc/cron.daily/update-notifier-common:
flashplugin-installer: downloading
http://archive.canonical.com/pool/partner/a/adobe-flashplugin/adobe-flashplugin_
11.2.202.233.orig.tar.gz
Installing from local file /tmp/tmpZsCTV4.gz
Flash Plugin installed.

There were indeed some flashplugin updates that I applied in the last days, but notethat the first two emails are for the *same* version. My laptop was probably in sleep over one night which might explain the day of silence.

/usr/share/package-data-downloads/flashplugin-installer dates of the 18th of April around midnight and /var/lib/update-notifier/package-data-downloads/flashplugin-installer of the 20th of April.

So I don't see why this should have run on the 20th.

But while checking the code, I believe I've actually found a bug in the handling of failed updates:
def hook_aged_out(hook_name):
        """Check if this hook has been failing consistently for >= 3 days"""

        failure_file = os.path.join(STAMPDIR, hook_name + '.failed')
        try:
                hook_date = os.stat(failure_file).st_ctime
                cur_time = os.times()[4]
                d = timedelta(microseconds=cur_time-hook_date)
                if d.days >= 3:
                        return True
        except OSError:
                pass
        except Exception:
                traceback.print_exc(file=sys.stderr)
        return False

os.times()[4] seems a completely bogus value for checking age:
python -c 'from datetime import timedelta; import os; hook_date = os.stat("/var/lib/update-notifier/package-data-downloads/flashplugin-installer").st_ctime; cur_time = os.times()[4]; microseconds = cur_time - hook_date; d= timedelta(microseconds=microseconds); print d.days; print microseconds; print cur_time; print hook_date'
-1
-1315376334.45
19523955.25
1334900289.7

(I used the successful stamp file rather than a failed stamp file, but it's the same problem.)

I believe you want:
python -c 'from datetime import datetime; import os; hook_date = datetime.fromtimestamp(os.stat("/var/lib/update-notifier/package-data-downloads/flashplugin-installer").st_ctime); cur_time = datetime.now(); d=cur_time - hook_date; print d.days; print cur_time; print hook_date'

Cheers,

ProblemType: Bug
DistroRelease: Ubuntu 12.04
Package: update-notifier-common 0.119ubuntu8
ProcVersionSignature: Ubuntu 3.2.0-18.28-generic 3.2.9
Uname: Linux 3.2.0-18-generic x86_64
ApportVersion: 2.0.1-0ubuntu5
Architecture: amd64
Date: Fri Apr 20 15:02:17 2012
PackageArchitecture: all
ProcEnviron:
 LANGUAGE=fr_FR:fr:en_GB:en
 TERM=xterm
 PATH=(custom, user)
 LANG=fr_FR.UTF-8
 SHELL=/bin/zsh
SourcePackage: update-notifier
UpgradeStatus: Upgraded to precise on 2009-12-07 (864 days ago)

Revision history for this message
Loïc Minier (lool) wrote :
Revision history for this message
Loïc Minier (lool) wrote :

The hook date check seem alright though, so I don't really know why it ran twice on the same flashplugin version.

Revision history for this message
Loïc Minier (lool) wrote :

/var/log/apt/history.log indicates that these upgrades happened:
flashplugin-installer:amd64 (11.2.202.233ubuntu1, 11.2.202.233ubuntu2) on 2012-04-20 from 01:55:05 to 02:02:17
flashplugin-installer:amd64 (11.2.202.228ubuntu3, 11.2.202.233ubuntu1) on 2012-04-17 from 12:51:22 to 12:56:24
flashplugin-installer:amd64 (11.2.202.228ubuntu1, 11.2.202.28ubuntu3) on 2012-04-16 from to 01:21:45

This explains the updates on the 17th, 18th and 20th; it's just that flashplugin wasn't correctly updated to a new version on the 17th, but the hook file had a newer timestamp which triggered a redownload of the same data.

summary: - Triggers multiple times
+ Broken timedate handling for failed hook runs
Changed in update-notifier (Ubuntu):
importance: Undecided → Medium
Steve Langasek (vorlon)
Changed in update-notifier (Ubuntu):
assignee: nobody → Steve Langasek (vorlon)
Steve Langasek (vorlon)
Changed in update-notifier (Ubuntu Precise):
importance: Undecided → Medium
assignee: nobody → Steve Langasek (vorlon)
status: New → Triaged
Changed in update-notifier (Ubuntu Quantal):
status: New → Triaged
Steve Langasek (vorlon)
Changed in update-notifier (Ubuntu Quantal):
status: Triaged → Fix Committed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package update-notifier - 0.119ubuntu9

---------------
update-notifier (0.119ubuntu9) quantal; urgency=low

  * fix data/Makefile.am to clean up all generated files.
  * fix wrong intltool-merge invocation.
  * data/package-data-downloads-failed{,-permanently}.in: work around a bug in
    intltool-merge rfc822deb handling that causes wrong syntax when the first
    line in the file is a translated field. LP: #993672.
  * use po2debconf instead of the upstream intltool-merge, since the latter
    doesn't actually handle multi-paragraph description fields correctly.
  * Fix package-data-downloader to do a correct timestamp comparison. Thanks
    to Loïc Minier for catching this. LP: #986183.
  * data/package-data-downloads-failed.in: use pkexec instead of gksudo, for
    compatibility with Kubuntu. Thanks to Jonathan Thomas for pointing out
    the correct fix. LP: #982032.
 -- Steve Langasek <email address hidden> Tue, 15 May 2012 16:16:08 -0700

Changed in update-notifier (Ubuntu Quantal):
status: Fix Committed → Fix Released
Revision history for this message
Chris Halse Rogers (raof) wrote : Please test proposed package

Hello Loïc, or anyone else affected,

Accepted update-notifier into precise-proposed. The package will build now and be available in a few hours. Please test and give feedback here. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you in advance!

Changed in update-notifier (Ubuntu Precise):
status: Triaged → Fix Committed
tags: added: verification-needed
Revision history for this message
Steve Langasek (vorlon) wrote :

I've verified this bugfix using the test case added to the bug description.

description: updated
tags: added: verification-done
removed: verification-needed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package update-notifier - 0.119ubuntu8.4

---------------
update-notifier (0.119ubuntu8.4) precise-proposed; urgency=low

  * Rebuild the source package with complete autotools support.

update-notifier (0.119ubuntu8.3) precise-proposed; urgency=low

  * po/*.po: the string '$packages' must not be translated, but we currently
    have no way to mark the string as such in the input files. LP: #1003100.

update-notifier (0.119ubuntu8.2) precise-proposed; urgency=low

  * fix data/Makefile.am to clean up all generated files.
  * fix wrong intltool-merge invocation.
  * data/package-data-downloads-failed{,-permanently}.in: work around a bug in
    intltool-merge rfc822deb handling that causes wrong syntax when the first
    line in the file is a translated field. LP: #993672.
  * use po2debconf instead of the upstream intltool-merge, since the latter
    doesn't actually handle multi-paragraph description fields correctly.
  * Fix package-data-downloader to do a correct timestamp comparison. Thanks
    to Loïc Minier for catching this. LP: #986183.
  * data/package-data-downloads-failed.in: use pkexec instead of gksudo, for
    compatibility with Kubuntu. Thanks to Jonathan Thomas for pointing out
    the correct fix. LP: #982032.
 -- Steve Langasek <email address hidden> Wed, 23 May 2012 00:27:10 +0000

Changed in update-notifier (Ubuntu Precise):
status: Fix Committed → Fix Released
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.