Skip to content

Commit

Permalink
fixes #5091; Ensure we don't wait on an exited process on Linux (#23743)
Browse files Browse the repository at this point in the history
Fixes #5091.

Ensure we don't wait on an exited process on Linux
  • Loading branch information
maleyva1 authored Jul 1, 2024
1 parent 4202b60 commit 288d5c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/pure/osproc.nim
Original file line number Diff line number Diff line change
Expand Up @@ -1416,6 +1416,8 @@ elif not defined(useNimRtl):
tmspec.tv_nsec = (timeout * 1_000_000)

try:
if not running(p):
return exitStatusLikeShell(p.exitStatus)
if clock_gettime(CLOCK_REALTIME, stspec) == -1:
raiseOSError(osLastError())
while true:
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:
discard

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

0 comments on commit 288d5c4

Please sign in to comment.