Add binary removal delay on Windows to avoid access denied (#2351)
Co-authored-by: Polina Sokolova <polinasok@users.noreply.github.com>
This commit is contained in:
parent
780bcac9cc
commit
54d0d56b9e
@ -170,13 +170,11 @@ func testOutput(t *testing.T, dlvbin, output string, delveCmds []string) (stdout
|
||||
|
||||
_, err = os.Stat(debugbin)
|
||||
if err == nil {
|
||||
if strings.ToLower(os.Getenv("TRAVIS")) == "true" && runtime.GOOS == "windows" {
|
||||
// Sometimes delve on Travis on Windows can't remove the built binary before
|
||||
// exiting and gets an "Access is denied" error when trying.
|
||||
// Just ignore it.
|
||||
// See: https://travis-ci.com/go-delve/delve/jobs/296325131
|
||||
return
|
||||
}
|
||||
// Sometimes delve on Windows can't remove the built binary before
|
||||
// exiting and gets an "Access is denied" error when trying.
|
||||
// This used to make this test flaky. See: https://travis-ci.com/go-delve/delve/jobs/296325131)
|
||||
// But we have now added a delay to gobuild.Remove. If this flakes again,
|
||||
// adjust it. Leaving temporary files behind can be annoying to users.
|
||||
t.Errorf("running %q: file %v was not deleted\nstdout is %q, stderr is %q", delveCmds, debugbin, stdout, stderr)
|
||||
return
|
||||
}
|
||||
|
||||
@ -6,6 +6,8 @@ import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"runtime"
|
||||
"time"
|
||||
|
||||
"github.com/go-delve/delve/pkg/config"
|
||||
"github.com/go-delve/delve/pkg/goversion"
|
||||
@ -15,6 +17,12 @@ import (
|
||||
// This can be used to remove the temporary binary generated for the session.
|
||||
func Remove(path string) {
|
||||
err := os.Remove(path)
|
||||
// Open files can be removed on Unix, but not on Windows, where there also appears
|
||||
// to be a delay in releasing the binary when the process exits. So we try again.
|
||||
if err != nil && runtime.GOOS == "windows" {
|
||||
time.Sleep(10 * time.Microsecond)
|
||||
err = os.Remove(path)
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintf(os.Stderr, "could not remove %v: %v\n", path, err)
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user