Skip to content

Commit

Permalink
fixes nim-lang#5091; Ensure we don't wait on an exited process
Browse files Browse the repository at this point in the history
  • Loading branch information
maleyva1 committed Jun 20, 2024
1 parent 646bd99 commit 498e32f
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/pure/osproc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1383,7 +1383,8 @@ elif not defined(useNimRtl):
s.tv_sec = b.tv_sec
s.tv_nsec = b.tv_nsec

if p.exitFlag:
# Ensure we don't wait on an exited process
if not(p.running()) and p.exitFlag:
return exitStatusLikeShell(p.exitStatus)

if timeout == -1:
Expand Down
18 changes: 18 additions & 0 deletions tests/osproc/twaitforexit.nim
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import std/[osproc, os, times]

block: # bug #5091
when defined(linux):
const filename = "false"
var p = startProcess(filename, options = {poStdErrToStdOut, poUsePath})
os.sleep(1000) # make sure process has exited already

let atStart = getTime()
const msWait = 2000

try:
discard waitForExit(p, msWait)
except OSError:
echo getCurrentExceptionMsg()

# check that we don't have to wait msWait milliseconds
doAssert(getTime() < atStart + milliseconds(msWait))

0 comments on commit 498e32f

Please sign in to comment.