#6185·wails

[v3] updater: failed downloads leave the temp dir behind (named-return shadows the deferred RemoveAll)

Author: Amir-Saatchi-NordCSCreated Sep 28, 2026Updated Sep 28, 2026
LabelsBugv3

Wails version family

v3

Exact Wails version

v3.0.0-beta.26 (pkg/updater; download.go is identical on master)

Operating System

Windows (the bug is platform-independent)

Description

When a download fails, Updater.download leaves its temp directory and the partial artifact behind (%TEMP%\wails-update-*\.artifact), although the doc comment says "On any error every artifact created by this function (file + enclosing directory) is removed before returning."

The cause is the named results together with the deferred cleanup:

go
func (u *Updater) download(ctx context.Context, p Provider, rel *Release) (path, dir string, err error) {
	dir, err = os.MkdirTemp("", "wails-update-*")
	...
	success := false
	defer func() {
		if !success {
			_ = os.RemoveAll(dir)
		}
	}()
	...
	return "", "", err   // sets dir = "" before the deferred func runs

return "", "", err assigns dir = "" before the deferred function runs, so it calls os.RemoveAll(""), which does nothing.

To Reproduce

  1. Serve a release whose download is cut off halfway (the server closes the connection).
  2. Call Check, then DownloadAndInstall. The download fails with unexpected EOF (stage download).
  3. Look in %TEMP%: a wails-update-* directory with a partial .artifact is left behind. This happened in 5 of 5 runs, 7.3 MB each.

Failures in the verify stage don't leak (0 of 5), and neither did a standalone "write a partial file, then delete it" test, so this is not antivirus holding the file.

Expected behaviour

The temp directory is removed on every error path.

Attempted Fixes

Capture the directory in a separate local for the deferred cleanup, for example tmpDir := dir right after MkdirTemp and defer func() { if !success { _ = os.RemoveAll(tmpDir) } }(). Or return the named values unchanged on error paths.

System Details

Windows 11 Pro 26200 (x64), Go 1.26.0, CGO_ENABLED=0, github.com/wailsapp/wails/v3 v3.0.0-beta.26. wails3 doctor was not run: the test app is built with plain go build.

Additional context

Related leftovers seen in the same test: staged artifacts stay in %TEMP% on every path that doesn't swap (a staged update that was never applied, helper exits 13, 14 and 17, a rejected Restart), and the helper log %TEMP%\wails-update-<pid>.log is never deleted.