Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

defer removing a binary after it's used causes OSError #10359

Closed
timotheecour opened this issue Jan 18, 2019 · 4 comments
Closed

defer removing a binary after it's used causes OSError #10359

timotheecour opened this issue Jan 18, 2019 · 4 comments

Comments

@timotheecour
Copy link
Member

timotheecour commented Jan 18, 2019

I don't have a minimal example and it may be hard to reproduce so feel free to close this issue; but just wanted to mention it.

I never saw that error before; it looks like a bug; it only happens on windows; it occurs when a binary is removed in a defer statement, the binary being only used inside the block.

seems unrelated to the corresponding PR #10353

https://ci.appveyor.com/project/Araq/nim/builds/21708811

git rev-parse HEAD
fb4968a

relevant code snippet:
$nim/tests/misc/tparseopt.nim

  block: # fix #9842
    let exe = buildDir / "D20190112T145450".addFileExt(ExeExt)
    defer: removeFile exe
    let args = @["a1b", "a2 b", "", "a4\"b", "a5'b", r"a6\b", "a7\'b"]
    let cmd = "$# c -r --verbosity:0 -o:$# -d:testament_tparseopt $# $#" %
      [getCurrentCompilerExe(), exe, currentSourcePath(),
          args.quoteShellCommand]
    var ret = execCmdEx(cmd, options = {})
    if ret.exitCode != 0:
      # before bug fix, running cmd would show:
      # sh: -c: line 0: unexpected EOF while looking for matching `"'\n
      echo "exitCode: ", ret.exitCode, " cmd:", cmd
      doAssert false
    stripLineEnd(ret.output)
    assertEquals ret.output,

error log from appveyor:

JOINED: tests/misc/tparamsindefault.nim C
JOINED: tests/misc/tparedef.nim C
JOINED: tests/misc/tparsecombnum.nim C
FAIL: tests/misc/tparseopt.nim C
Test "tests\misc\tparseopt.nim" in category "misc"
Failure: reExitcodesDiffer
Expected:
exitcode: 0
Gotten:
exitcode: 1
Output:
parseopt
first round
kind: cmdLongOption	key:val  --  left:
second round
kind: cmdLongOption	key:val  --  left:
kind: cmdLongOption	key:val  --  debug:3
kind: cmdShortOption	key:val  --  l:4
kind: cmdShortOption	key:val  --  r:2
cmdLongOption foo
cmdLongOption path
parseoptNoVal
kind: cmdLongOption	key:val  --  left:
kind: cmdLongOption	key:val  --  debug:3
kind: cmdShortOption	key:val  --  l:
kind: cmdShortOption	key:val  --  r:2
kind: cmdLongOption	key:val  --  debug:2
kind: cmdLongOption	key:val  --  debug:1
kind: cmdShortOption	key:val  --  r:1
kind: cmdShortOption	key:val  --  r:0
kind: cmdShortOption	key:val  --  l:
kind: cmdShortOption	key:val  --  r:4
parseopt2
first round
kind: cmdLongOption	key:val  --  left:
second round
kind: cmdLongOption	key:val  --  left:
kind: cmdLongOption	key:val  --  debug:3
kind: cmdShortOption	key:val  --  l:4
kind: cmdShortOption	key:val  --  r:2
tparseopt.nim(124)       tparseopt
os.nim(1252)             removeFile
oserr.nim(67)            raiseOSError
Error: unhandled exception: The process cannot access the file because it is being used by another process.
 [OSError]
JOINED: tests/misc/tpos.nim C
PASS: tests/misc/tprep.nim C                                       ( 2.35937548 secs)
timotheecour added a commit to timotheecour/Nim that referenced this issue Jan 18, 2019
@timotheecour timotheecour changed the title defer: removeFile exe gives: The process cannot access the file because it is being used by another process defer removing an binary after it's used causes OSError Jan 18, 2019
@timotheecour timotheecour changed the title defer removing an binary after it's used causes OSError defer removing a binary after it's used causes OSError Jan 18, 2019
Araq pushed a commit that referenced this issue Jan 18, 2019
* fix #9629 every binary cmd line option allows on/off/empty=on

* workaround refs #10359
@nc-x
Copy link
Contributor

nc-x commented Jan 18, 2019

works fine locally (windows 10 x64)

@timotheecour
Copy link
Member Author

ya may be hard to repro; closing for now; if pops up again we can re-open ; thx for trying it locally

@timotheecour
Copy link
Member Author

reopening as this happened in a completely unrelated PR (by @BontaVlad #10228) again: https://ci.appveyor.com/project/dom96/nim/builds/21635870

JOINED: tests/misc/tparamsindefault.nim C
JOINED: tests/misc/tparedef.nim C
JOINED: tests/misc/tparsecombnum.nim C
FAIL: tests/misc/tparseopt.nim C
Test "tests\misc\tparseopt.nim" in category "misc"
Failure: reExitcodesDiffer
Expected:
exitcode: 0
Gotten:
exitcode: 1
Output:
parseopt
first round
kind: cmdLongOption	key:val  --  left:
second round
kind: cmdLongOption	key:val  --  left:
kind: cmdLongOption	key:val  --  debug:3
kind: cmdShortOption	key:val  --  l:4
kind: cmdShortOption	key:val  --  r:2
cmdLongOption foo
cmdLongOption path
parseoptNoVal
kind: cmdLongOption	key:val  --  left:
kind: cmdLongOption	key:val  --  debug:3
kind: cmdShortOption	key:val  --  l:
kind: cmdShortOption	key:val  --  r:2
kind: cmdLongOption	key:val  --  debug:2
kind: cmdLongOption	key:val  --  debug:1
kind: cmdShortOption	key:val  --  r:1
kind: cmdShortOption	key:val  --  r:0
kind: cmdShortOption	key:val  --  l:
kind: cmdShortOption	key:val  --  r:4
parseopt2
first round
kind: cmdLongOption	key:val  --  left:
second round
kind: cmdLongOption	key:val  --  left:
kind: cmdLongOption	key:val  --  debug:3
kind: cmdShortOption	key:val  --  l:4
kind: cmdShortOption	key:val  --  r:2
tparseopt.nim(121)       tparseopt
os.nim(1252)             removeFile
oserr.nim(67)            raiseOSError
Error: unhandled exception: The process cannot access the file because it is being used by another process.
 [OSError]
JOINED: tests/misc/tpos.nim C

so there is a bug, we just need to find a minimal test case (and perhaps it is a flaky one)

note that I've patched tests/misc/tparseopt.nim as workaround but bug is still there

@Araq
Copy link
Member

Araq commented Aug 17, 2019

IME Windows' file deletion is simply buggy. Even Windows's very own explorer sometimes fails with errors like these. Closing.

@Araq Araq closed this as completed Aug 17, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants