worker/uniter: Remove temp download files #6314

Merged
merged 3 commits into from Sep 25, 2016

Conversation

Projects
None yet
3 participants
Contributor

mjs commented Sep 23, 2016

The temporary files created during charm downloads were being left behind if an error occured. In some cases (a repeating permanent error) this would lead to disk space exhaustion.

The uniter will now also clear any temporary charm download files for the unit it manages when it starts. Although this shouldn't happen now, previous versions of Juju could leave a significant amount of data behind from failed download attempts.

This completes the fixes for https://bugs.launchpad.net/juju/+bug/1626304.

mjs added some commits Sep 23, 2016

worker/uniter/charm: Remove temp files on error
The temporary files created during charm downloads were being left
behind if an error occured. In some cases (a repeating permanent error)
this would lead to disk space exhaustion.

Part of the fix for https://bugs.launchpad.net/juju/+bug/1626304
worker/uniter/charm: Added ClearDownloads
This can be used to clear out any temporary download files that may be
hanging around in a unit's charm download directory.
worker/uniter/charm/bundles.go
+ for _, entry := range entries {
+ path := filepath.Join(downloadDir, entry.Name())
+ if err = os.RemoveAll(path); err != nil {
+ return
@mjs

mjs Sep 23, 2016

Contributor

Thinking about it, this should probably keep going with other entries even if one fails to remove to maximise the amount of disk space returned to the OS.

@axw

axw Sep 23, 2016

Member

+1, though I'm not sure how helpful it'll be in practice. Assuming it's a transient error, the worker should restart and eventually clean them all up.

worker/uniter/uniter.go
@@ -236,6 +236,9 @@ func (u *Uniter) init(unitTag names.UnitTag) (err error) {
u.storage = storageAttachments
u.addCleanup(storageAttachments.Stop)
+ if err := charm.ClearDownloads(u.paths.State.BundlesDir); err != nil {
+ return errors.Annotatef(err, "cannot clear downloads")
@mjs

mjs Sep 23, 2016

Contributor

This probably shouldn't be fatal should it?... Might be best to just warn instead.

@axw

axw Sep 23, 2016

Member

I'd prefer if we would just bail, but let's warn for now to be on the safe side. Something external could block the deletion of the directory/files by holding onto them. Shouldn't happen, but it's possible, and I don't think we should risk that in a maintenance branch.

axw approved these changes Sep 23, 2016

LGTM, but I think we could probably simplify ClearDownloads.

worker/uniter/charm/bundles.go
+func ClearDownloads(bundlesDir string) (err error) {
+ defer errors.DeferredAnnotatef(&err, "unable to clear bundle downloads")
+
+ downloadDir := downloadsPath(bundlesDir)
@axw

axw Sep 23, 2016

Member

Maybe just os.RemoveAll(downloadDir)? The downloader will recreate it as necessary.

@mjs

mjs Sep 25, 2016

Contributor

Done

worker/uniter/charm/bundles.go
+ for _, entry := range entries {
+ path := filepath.Join(downloadDir, entry.Name())
+ if err = os.RemoveAll(path); err != nil {
+ return
@mjs

mjs Sep 23, 2016

Contributor

Thinking about it, this should probably keep going with other entries even if one fails to remove to maximise the amount of disk space returned to the OS.

@axw

axw Sep 23, 2016

Member

+1, though I'm not sure how helpful it'll be in practice. Assuming it's a transient error, the worker should restart and eventually clean them all up.

worker/uniter/uniter.go
@@ -236,6 +236,9 @@ func (u *Uniter) init(unitTag names.UnitTag) (err error) {
u.storage = storageAttachments
u.addCleanup(storageAttachments.Stop)
+ if err := charm.ClearDownloads(u.paths.State.BundlesDir); err != nil {
+ return errors.Annotatef(err, "cannot clear downloads")
@mjs

mjs Sep 23, 2016

Contributor

This probably shouldn't be fatal should it?... Might be best to just warn instead.

@axw

axw Sep 23, 2016

Member

I'd prefer if we would just bail, but let's warn for now to be on the safe side. Something external could block the deletion of the directory/files by holding onto them. Shouldn't happen, but it's possible, and I don't think we should risk that in a maintenance branch.

worker/uniter: Clear temp download files on start
The uniter will now clear any temporary charm download files for itself
when it starts. Although this shouldn't happen now, previous versions of
Juju could leave a signiciant amount of data behind from failed download
attempts.

Part of the fix for https://bugs.launchpad.net/juju/+bug/1626304
Contributor

mjs commented Sep 25, 2016

$$merge$$

Contributor

jujubot commented Sep 25, 2016

Status: merge request accepted. Url: http://juju-ci.vapour.ws:8080/job/github-merge-juju

@jujubot jujubot merged commit 19c47ec into juju:1.25 Sep 25, 2016

@mjs mjs deleted the mjs:1626304-clean-up-uniter-downloads-1.25 branch Sep 26, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment