Add retry logic to snap-tool to make downloads more resilient

Bug #1837871 reported by Tobias Koch
8
This bug affects 1 person
Affects Status Importance Assigned to Milestone
livecd-rootfs (Ubuntu)
Fix Released
High
Unassigned
Bionic
Fix Released
Undecided
Unassigned
Disco
Fix Released
Undecided
Unassigned

Bug Description

[Impact]

* livecd-rootfs builds will fail immediately when a snap-tool invocation fails to contact the snapstore because of ephemeral connection problems or a transient error on the server side.

* The snap-tool script included with livecd-rootfs in Eoan has been enhanced to retry on connection errors and 5xx server errors reducing the likelihood of image builds breaking due to a flaky connection or a server hiccup.

[Test Cases]

* Download core, core18 snaps using both `snap download <snap-name>` and `snap-tool download <snap-name>` and make sure the downloads are identical.

* Invoke `snap-tool info <snap-name>` for a few snaps, e.g. review-gator, lpshipit, azure-cli and verify that all fields carry correct information.

* Test the backoff/retry logic using the following procedure:

Make netcat listen on port 12345

    netcat -l -p 12345

Create a symlink from snaptool.py to snap-tool and import the ExpBackoffHTTPClient class from a Python session:

    ln -s snap-tool snaptool.py

    python3
    from snaptool import ExpBackoffHTTPClient
    http_client = ExpBackoffHTTPClient()
    request = http_client.get("http://127.0.0.1:12345/")
    request.text()

Go back to the terminal where you invoked netcat and stop it. snap-tool should print the following and then fail:

WARNING: failed to open URL 'http://127.0.0.1:12345/': Remote end closed connection without response
Retrying HTTP request in 2 seconds...
WARNING: failed to open URL 'http://127.0.0.1:12345/': <urlopen error [Errno 111] Connection refused>
Retrying HTTP request in 4 seconds...

Repeat the procedure above but instead of stopping netcat, paste the following response:

HTTP/1.1 503 Error

and hit enter twice. You should see

WARNING: failed to open URL 'http://127.0.0.1:12345/': HTTP Error 503: Error
Retrying HTTP request in 2 seconds...

Repeat the above pasting "HTTP/1.1 404 Not found" instead. The snap-tool should fail immediately.

[Regression Potential]

 * Tool logic and http request headers/body are unchanged, only the way connections are built has been modified. The expectation is that this will be more robust and testing in devel hasn't surfaced any bugs, but there is a slight risk that the tool's behavior has changed in unobvious corner cases that were missed during testing.

Tobias Koch (tobijk)
summary: - Backport snap-tool backoff/retry logic
+ Add retry logic to snap-tool to make downloads more resilient
Revision history for this message
Tobias Koch (tobijk) wrote :
Revision history for this message
Tobias Koch (tobijk) wrote :
Changed in livecd-rootfs (Ubuntu):
status: New → In Progress
tags: added: id-5d0a349876579b42ed84d920
Mathew Hodson (mhodson)
Changed in livecd-rootfs (Ubuntu):
importance: Undecided → Low
Changed in livecd-rootfs (Ubuntu):
importance: Low → High
Revision history for this message
Tobias Koch (tobijk) wrote :
Revision history for this message
Adam Conrad (adconrad) wrote : Please test proposed package

Hello Tobias, or anyone else affected,

Accepted livecd-rootfs into disco-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/livecd-rootfs/2.578.7 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-disco to verification-done-disco. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-disco. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Changed in livecd-rootfs (Ubuntu Disco):
status: New → Fix Committed
tags: added: verification-needed verification-needed-disco
Changed in livecd-rootfs (Ubuntu):
status: In Progress → Fix Released
Changed in livecd-rootfs (Ubuntu Bionic):
status: New → Fix Committed
tags: added: verification-needed-bionic
Revision history for this message
Adam Conrad (adconrad) wrote :

Hello Tobias, or anyone else affected,

Accepted livecd-rootfs into bionic-proposed. The package will build now and be available at https://launchpad.net/ubuntu/+source/livecd-rootfs/2.525.29 in a few hours, and then in the -proposed repository.

Please help us by testing this new package. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation on how to enable and use -proposed. Your feedback will aid us getting this update out to other Ubuntu users.

If this package fixes the bug for you, please add a comment to this bug, mentioning the version of the package you tested and change the tag from verification-needed-bionic to verification-done-bionic. If it does not fix the bug for you, please add a comment stating that, and change the tag to verification-failed-bionic. In either case, without details of your testing we will not be able to proceed.

Further information regarding the verification process can be found at https://wiki.ubuntu.com/QATeam/PerformingSRUVerification . Thank you in advance for helping!

N.B. The updated package will be released to -updates after the bug(s) fixed by this package have been verified and the package has been in -proposed for a minimum of 7 days.

Tobias Koch (tobijk)
tags: added: verification-done-disco
removed: verification-needed-disco
Revision history for this message
Tobias Koch (tobijk) wrote :

Tested and confirmed functionality on Disco and Bionic.

tags: added: verification-done-bionic
removed: verification-needed-bionic
Revision history for this message
Ubuntu SRU Bot (ubuntu-sru-bot) wrote : Autopkgtest regression report (livecd-rootfs/2.578.7)

All autopkgtests for the newly accepted livecd-rootfs (2.578.7) for disco have finished running.
The following regressions have been reported in tests triggered by the package:

ubuntu-image/1.7+19.04ubuntu1 (s390x)

Please visit the excuses page listed below and investigate the failures, proceeding afterwards as per the StableReleaseUpdates policy regarding autopkgtest regressions [1].

https://people.canonical.com/~ubuntu-archive/proposed-migration/disco/update_excuses.html#livecd-rootfs

[1] https://wiki.ubuntu.com/StableReleaseUpdates#Autopkgtest_Regressions

Thank you!

Revision history for this message
Tobias Koch (tobijk) wrote :

I see two errors, both of which are unrelated to this update:

1) A call to "snap prepare-image" fails because download of a model assertion fails.
2) A FileNotFoundError in test_does_not_fit

None of these involve a snap-tool invocation.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package livecd-rootfs - 2.525.29

---------------
livecd-rootfs (2.525.29) bionic; urgency=medium

  * Add retry logic to snap-tool to make downloads more resilient.
    (LP: #1837871)

 -- Tobias Koch <email address hidden> Mon, 26 Aug 2019 13:41:50 +0200

Changed in livecd-rootfs (Ubuntu Bionic):
status: Fix Committed → Fix Released
Revision history for this message
Brian Murray (brian-murray) wrote : Update Released

The verification of the Stable Release Update for livecd-rootfs has completed successfully and the package has now been released to -updates. Subsequently, the Ubuntu Stable Release Updates Team is being unsubscribed and will not receive messages about this bug report. In the event that you encounter a regression using the package from -updates please report a new bug using ubuntu-bug and tag the bug report regression-update so we can easily find any regressions.

Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package livecd-rootfs - 2.578.7

---------------
livecd-rootfs (2.578.7) disco; urgency=medium

  [ Tobias Koch ]
  * Add retry logic to snap-tool to make downloads more resilient.
    (LP: #1837871)

 -- Tobias Koch <email address hidden> Mon, 26 Aug 2019 13:36:36 +0200

Changed in livecd-rootfs (Ubuntu Disco):
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.