Skip to content

Commit

Permalink
avoid overflow on functionality to print backtrace of safepoint strag…
Browse files Browse the repository at this point in the history
…gler
  • Loading branch information
d-netto committed Mar 1, 2025
1 parent f5ce249 commit 273556c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/safepoint.c
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ void jl_gc_wait_for_the_world(jl_ptls_t* gc_all_tls_states, int gc_n_threads)
uv_mutex_unlock(&safepoint_lock);
}
else {
const int64_t timeout = jl_options.timeout_for_safepoint_straggler_s * 1000000000; // convert to nanoseconds
const int64_t timeout = jl_options.timeout_for_safepoint_straggler_s * 1000000000LL; // convert to nanoseconds
int ret = 0;
uv_mutex_lock(&safepoint_lock);
if (!jl_atomic_load_relaxed(&ptls2->gc_state)) {
Expand Down
26 changes: 14 additions & 12 deletions test/threads_exec.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1630,25 +1630,27 @@ end
program = "
function main()
t = Threads.@spawn begin
ccall(:uv_sleep, Cvoid, (Cuint,), 5000)
ccall(:uv_sleep, Cvoid, (Cuint,), 20_000)
end
# Force a GC
ccall(:uv_sleep, Cvoid, (Cuint,), 1000)
ccall(:uv_sleep, Cvoid, (Cuint,), 1_000)
GC.gc()
wait(t)
end
main()
"
tmp_output_filename = tempname()
tmp_output_file = open(tmp_output_filename, "w")
if isnothing(tmp_output_file)
error("Failed to open file $tmp_output_filename")
end
run(pipeline(`$(Base.julia_cmd()) --threads=4 --timeout-for-safepoint-straggler=1 -e $program`, stderr=tmp_output_file))
# Check whether we printed the straggler's backtrace
@test !isempty(read(tmp_output_filename, String))
close(tmp_output_file)
rm(tmp_output_filename)
for timeout in ("1", "4", "16")
tmp_output_filename = tempname()
tmp_output_file = open(tmp_output_filename, "w")
if isnothing(tmp_output_file)
error("Failed to open file $tmp_output_filename")
end
run(pipeline(`$(Base.julia_cmd()) --threads=4 --timeout-for-safepoint-straggler=$(timeout) -e $program`, stderr=tmp_output_file))
# Check whether we printed the straggler's backtrace
@test !isempty(read(tmp_output_filename, String))
close(tmp_output_file)
rm(tmp_output_filename)
end
end

end # main testset

0 comments on commit 273556c

Please sign in to comment.