From b054893f95f289cd4e7c02b8112c4e9ac45b031c Mon Sep 17 00:00:00 2001 From: Venkatesh Dayananda Date: Fri, 11 Apr 2025 18:39:02 +0530 Subject: [PATCH 1/7] squash --- src/DocumentationGenerator.jl | 5 ++- src/utils/runners.jl | 59 +++++++++++++++++++++++++++++------ test/runtests.jl | 3 +- 3 files changed, 55 insertions(+), 12 deletions(-) diff --git a/src/DocumentationGenerator.jl b/src/DocumentationGenerator.jl index 4898f0ab..6f344981 100644 --- a/src/DocumentationGenerator.jl +++ b/src/DocumentationGenerator.jl @@ -156,7 +156,10 @@ function build_documentation( # wait for all queued processes to finish for proc in process_queue - wait(proc) + pid = getpid(proc) + pgid = get_pgid(pid) + @info "detected session id for process $(pid): $(pgid)" + wait(proc, false) end end diff --git a/src/utils/runners.jl b/src/utils/runners.jl index a4af62e5..ba5d2132 100644 --- a/src/utils/runners.jl +++ b/src/utils/runners.jl @@ -9,11 +9,19 @@ Runs `command` and pipes all output to `log`. The process will be terminated aft and `verbose` determines whether meta-logs ("process started" etc.) will be printed. """ function run_with_timeout( - command; log=stdout, timeout = 40*60, name = "", - wait_time = 1, verbose = true, kill_timeout = 60, - max_timeout = 3*60*60 + command; + log = stdout, + timeout = 40 * 60, + name = "", + wait_time = 1, + verbose = true, + kill_timeout = 60, + max_timeout = 3 * 60 * 60, ) - print_interval = 60/wait_time + pushfirst!(command.exec, "setsid") + @info ">> starting" command timeout kill_timeout max_timeout + + print_interval = 60 / wait_time print_in = print_interval out_io = IOBuffer() @@ -35,7 +43,7 @@ function run_with_timeout( io = try log isa String ? open(log, "w") : log catch err - @error "Error opening logfile, falling back to stdout" error=err + @error "Error opening logfile, falling back to stdout" error = err logfallback = true stdout end @@ -47,13 +55,13 @@ function run_with_timeout( total = time() - job_start if elapsed > timeout || total > max_timeout verbose && @info("Terminating $name") - kill(process) + kill_pg(process) # Handle scenarios where SIGTERM is blocked/ignored/handled by the process start_time = time() while process_running(process) if time() - start_time > kill_timeout verbose && @info("Killing $name") - kill(process, Base.SIGKILL) + kill_pg(process, true) end sleep(5) end @@ -79,9 +87,10 @@ function run_with_timeout( end verbose && println() - verbose && @info("$name completed in $(round(time() - tstart, digits=1)) seconds") + verbose && + @info("$name completed in $(round(time() - tstart, digits=1)) seconds") catch err - @error "Error while running $(name) with timeout." error=err + @error "Error while running $(name) with timeout." error = err finally errstr, outstr = readstr_buffer.((out_io, err_io)) isempty(outstr) || println(io, outstr) @@ -103,3 +112,35 @@ end function readstr_buffer(x::IOBuffer) return String(take!(x)) end + +function get_pgid(pid::Int32) + out = try + readchomp(`ps -o pgid= -p $pid`) + catch ex + @warn("Failed to fetch pgid", exception = (ex, catch_backtrace())) + nothing + end + isnothing(out) && return nothing + return parse(Int32, strip(out)) +end + +function kill_pg(p::Base.Process, force = false) + pgid = get_pgid(getpid(p)) + if isnothing(pgid) + @warn "No process group found for $process" + kill(p) + else + kill_process_group(pgid, force) + end +end + +function kill_process_group(pid::Int32, force) + pgid = get_pgid(pid) + type = if force + "KILL" + else + "TERM" + end + cmd = ["kill", "-$type", "--", "-$pgid"] + run(Cmd(cmd)) +end diff --git a/test/runtests.jl b/test/runtests.jl index b9b74126..5c38ce25 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -18,7 +18,6 @@ const julia = first(Base.julia_cmd()) """ proc, _ = DocumentationGenerator.run_with_timeout(`$julia -e $str`, timeout=7) wait(proc) - @test !success(proc) @test !isfile(tempfile) end @@ -297,7 +296,7 @@ end success = [true], doctype = ["documenter"], using_failed = [false], - ), + ) ] basepath = @__DIR__ From 6b5d9a9d0bc85478ca1fe6581d50821a9887c4db Mon Sep 17 00:00:00 2001 From: Venkatesh Dayananda Date: Fri, 11 Apr 2025 18:42:37 +0530 Subject: [PATCH 2/7] fix --- src/DocumentationGenerator.jl | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/DocumentationGenerator.jl b/src/DocumentationGenerator.jl index 6f344981..1c7ab010 100644 --- a/src/DocumentationGenerator.jl +++ b/src/DocumentationGenerator.jl @@ -159,7 +159,11 @@ function build_documentation( pid = getpid(proc) pgid = get_pgid(pid) @info "detected session id for process $(pid): $(pgid)" - wait(proc, false) + if VERSION < v"1.11" + wait(proc) + else + wait(proc, false) + end end end From 2ce73fa5fd37ab40cb876591cd06e9773f404db5 Mon Sep 17 00:00:00 2001 From: Venkatesh Dayananda Date: Fri, 11 Apr 2025 18:58:40 +0530 Subject: [PATCH 3/7] fix --- src/DocumentationGenerator.jl | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/DocumentationGenerator.jl b/src/DocumentationGenerator.jl index 1c7ab010..39afa977 100644 --- a/src/DocumentationGenerator.jl +++ b/src/DocumentationGenerator.jl @@ -156,6 +156,8 @@ function build_documentation( # wait for all queued processes to finish for proc in process_queue + t = timedwait(x -> process_running(proc) || process_exited(proc), 20) + t == :timed_out && error("Process failed to start") pid = getpid(proc) pgid = get_pgid(pid) @info "detected session id for process $(pid): $(pgid)" From 185c81a950458f140e87b572218c48dd88e3083d Mon Sep 17 00:00:00 2001 From: Venkatesh Dayananda Date: Fri, 11 Apr 2025 20:00:30 +0530 Subject: [PATCH 4/7] fix --- src/DocumentationGenerator.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/DocumentationGenerator.jl b/src/DocumentationGenerator.jl index 39afa977..b96bbdbb 100644 --- a/src/DocumentationGenerator.jl +++ b/src/DocumentationGenerator.jl @@ -156,7 +156,7 @@ function build_documentation( # wait for all queued processes to finish for proc in process_queue - t = timedwait(x -> process_running(proc) || process_exited(proc), 20) + t = timedwait(() -> process_running(proc) || process_exited(proc), 20) t == :timed_out && error("Process failed to start") pid = getpid(proc) pgid = get_pgid(pid) From b3639e4a1dd72c8a93ff78d6f9659fbf4b2c3597 Mon Sep 17 00:00:00 2001 From: Venkatesh Dayananda Date: Fri, 11 Apr 2025 20:12:00 +0530 Subject: [PATCH 5/7] fix --- src/DocumentationGenerator.jl | 5 ----- 1 file changed, 5 deletions(-) diff --git a/src/DocumentationGenerator.jl b/src/DocumentationGenerator.jl index b96bbdbb..9b433450 100644 --- a/src/DocumentationGenerator.jl +++ b/src/DocumentationGenerator.jl @@ -156,11 +156,6 @@ function build_documentation( # wait for all queued processes to finish for proc in process_queue - t = timedwait(() -> process_running(proc) || process_exited(proc), 20) - t == :timed_out && error("Process failed to start") - pid = getpid(proc) - pgid = get_pgid(pid) - @info "detected session id for process $(pid): $(pgid)" if VERSION < v"1.11" wait(proc) else From ef371c3465bdce1a3af3f045593b2103ff5cee42 Mon Sep 17 00:00:00 2001 From: Venkatesh Dayananda Date: Mon, 14 Apr 2025 15:12:32 +0530 Subject: [PATCH 6/7] fix --- test/runtests.jl | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/test/runtests.jl b/test/runtests.jl index 5c38ce25..cbca22f9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -265,12 +265,7 @@ end using_failed = [false], ) else - (; - p..., - installs = [false], - success = [false], - doctype = ["missing"], - ) + (; p..., installs = [false], success = [false], doctype = ["missing"]) end end, ( @@ -296,20 +291,38 @@ end success = [true], doctype = ["documenter"], using_failed = [false], - ) + ), + ( + name = "NetworkDynamics", + url = "https://github.com/JuliaDynamics/NetworkDynamics.jl.git", + uuid = "22e9dc34-2a0d-11e9-0de0-8588d035468b", + versions = [v"0.9.16"], + server_type = "github", + api_url = "", + installs = [true], + success = [false], + doctype = ["documenter"], + using_failed = [false], + ), ] basepath = @__DIR__ rm(joinpath(basepath, "build"), force = true, recursive = true) DocumentationGenerator.build_documentation( - packages, basepath = basepath, filter_versions = identity, processes = 6 + packages, + basepath = basepath, + filter_versions = identity, + processes = 6, + timeout = 300, ) build = joinpath(basepath, "build") @testset "build folder" begin for pkg in packages - pkgbuild = joinpath(build, DocumentationGenerator.get_docs_dir(pkg.name, pkg.uuid)) + !pkg.success[1] && continue + pkgbuild = + joinpath(build, DocumentationGenerator.get_docs_dir(pkg.name, pkg.uuid)) @test isdir(pkgbuild) @testset "$(pkg.name): $(version)" for (i, version) in enumerate(pkg.versions) log = joinpath(pkgbuild, "$(version).log") From e41b000f307de85ab45359c91e5a0e553b15f91c Mon Sep 17 00:00:00 2001 From: Venkatesh Dayananda Date: Mon, 14 Apr 2025 15:39:04 +0530 Subject: [PATCH 7/7] fox --- test/runtests.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/runtests.jl b/test/runtests.jl index cbca22f9..d93b70e6 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -314,7 +314,7 @@ end basepath = basepath, filter_versions = identity, processes = 6, - timeout = 300, + timeout = 600, ) build = joinpath(basepath, "build")