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

insert backtrace printing into user-facing JL_CATCH #38201

Merged
merged 1 commit into from
Oct 29, 2020
Merged

Conversation

vchuravy
Copy link
Member

In #38134 (comment) I found it impossible to tell
which finalizer is to blame. With this a stacktrace is being printed:

julia> yield(t)
error in running finalizer: ErrorException("task switch not allowed from inside gc finalizer")
jl_error at /home/vchuravy/src/julia/src/rtutils.c:41
jl_switch at /home/vchuravy/src/julia/src/task.c:502
try_yieldto at ./task.jl:684
yieldto at ./task.jl:679 [inlined]
yieldto at ./task.jl:677 [inlined]
#9 at ./REPL[4]:11
_jl_invoke at /home/vchuravy/src/julia/src/gf.c:2172 [inlined]
jl_apply_generic at /home/vchuravy/src/julia/src/gf.c:2373
jl_apply at /home/vchuravy/src/julia/src/julia.h:1691 [inlined]
run_finalizer at /home/vchuravy/src/julia/src/gc.c:276

In this example the finalizer is #9 at ./REPL[4]:11

Copy link
Member

@Sacha0 Sacha0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Love it! :)

@vtjnash
Copy link
Member

vtjnash commented Oct 28, 2020

@vchuravy
Copy link
Member Author

Yeah on windows the output get's mangled.

error in running finalizer: jl_error at /cygdrive/c/buildbot/worker/package_win32/build/src\rtutils.c:41
jl_switch at /cygdrive/c/buildbot/worker/package_win32/build/src\task.c:502
try_yieldto at .\task.jl:684
yieldto at .\task.jl:679 [inlined]
yieldto at .\task.jl:677 [inlined]
#119 at C:\Users\vchuravy\Desktop\task.jl:10
jl_fptr_args at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:1960
_jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2191 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2373
jl_apply at /cygdrive/c/buildbot/worker/package_win32/build/src\julia.h:1691 [inlined]
run_finalizer at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:276
jl_gc_run_finalizers_in_list at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:363
run_finalizers at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:391 [inlined]
run_finalizers at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:370
jl_gc_collect at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:3198
gc at .\gcutils.jl:94 [inlined]
gc at .\gcutils.jl:94 [inlined]
macro expansion at C:\Users\vchuravy\Desktop\task.jl:13 [inlined]
#125 at .\task.jl:118
unknown function (ip: 1f6ad65d)
_jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2191 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2373
jl_apply at /cygdrive/c/buildbot/worker/package_win32/build/src\julia.h:1691 [inlined]
start_task at /cygdrive/c/buildbot/worker/package_win32/build/src\task.c:821
jl_error at /cygdrive/c/buildbot/worker/package_win32/build/src\rtutils.c:41
jl_switch at /cygdrive/c/buildbot/worker/package_win32/build/src\task.c:502
try_yieldto at .\task.jl:684
wait at .\task.jl:753 [inlined]
yield at .\task.jl:646
#117 at C:\Users\vchuravy\Desktop\task.jl:9
jl_fptr_args at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:1960
_jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2191 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2373
jl_apply at /cygdrive/c/buildbot/worker/package_win32/build/src\julia.h:1691 [inlined]
run_finalizer at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:276
jl_gc_run_finalizers_in_list at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:363
run_finalizers at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:391 [inlined]
run_finalizers at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:370
jl_gc_collect at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:3198
gc at .\gcutils.jl:94 [inlined]
gc at .\gcutils.jl:94 [inlined]
macro expansion at C:\Users\vchuravy\Desktop\task.jl:13 [inlined]
#125 at .\task.jl:118
unknown function (ip: 1f6ad65d)
_jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2191 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2373
jl_apply at /cygdrive/c/buildbot/worker/package_win32/build/src\julia.h:1691 [inlined]
start_task at /cygdrive/c/buildbot/worker/package_win32/build/src\task.c:821
jl_error at /cygdrive/c/buildbot/worker/package_win32/build/src\rtutils.c:41
jl_switch at /cygdrive/c/buildbot/worker/package_win32/build/src\task.c:502
try_yieldto at .\task.jl:684
wait at .\task.jl:753 [inlined]
wait at .\condition.jl:106
_trywait at .\asyncevent.jl:111
wait at .\asyncevent.jl:129 [inlined]
sleep at .\asyncevent.jl:214
#115 at C:\Users\vchuravy\Desktop\task.jl:8
jl_fptr_args at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:1960
_jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2191 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2373
jl_apply at /cygdrive/c/buildbot/worker/package_win32/build/src\julia.h:1691 [inlined]
run_finalizer at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:276
jl_gc_run_finalizers_in_list at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:363
run_finalizers at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:391 [inlined]
run_finalizers at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:370
jl_gc_collect at /cygdrive/c/buildbot/worker/package_win32/build/src\gc.c:3198
gc at .\gcutils.jl:94 [inlined]
gc at .\gcutils.jl:94 [inlined]
macro expansion at C:\Users\vchuravy\Desktop\task.jl:13 [inlined]
#125 at .\task.jl:118
unknown function (ip: 1f6ad65d)
_jl_invoke at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2191 [inlined]
jl_apply_generic at /cygdrive/c/buildbot/worker/package_win32/build/src\gf.c:2373
jl_apply at /cygdrive/c/buildbot/worker/package_win32/build/src\julia.h:1691 [inlined]
start_task at /cygdrive/c/buildbot/worker/package_win32/build/src\task.c:821
ErrorException("task switch not allowed from inside gc finalizer")
error in running finalizer: ErrorException("task switch not allowed from inside gc finalizer")
error in running finalizer: ErrorException("task switch not allowed from inside gc finalizer")

@vtjnash
Copy link
Member

vtjnash commented Oct 28, 2020

True, I guess it's not good to intermix writes to JL_STDERR with STDERR_FILENO

src/jlapi.c Show resolved Hide resolved
Since `jlbacktrace` uses `STDERR_FILENO` directly
we have to be a bit careful to avoid mangled errors
(particularily on Windows), so we use `STDERR_FILENO`
directly, when also using `jlbacktrace`.
@@ -492,6 +492,9 @@ static int exec_program(char *program)
jl_load(jl_main_module, program);
}
JL_CATCH {
// TODO: It is possible for this output
// to be mangled due to `jlbacktrace`
// printing directly to STDERR_FILENO.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is it possible to resolve this as you've done elsewhere then?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It wasn't immediately clear to me how to do so. The code mixes JL_STDERR and jl_stderr_objs and I presume it does so for a reason. I am not sure if it is gurantueed that hose two streams will be the same.

Some git archeology shows that this is code from the ancient times.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yes I see. So it seems that errs could certainly be pointing to some other stream if redirect_stderr was called. I think the fix here, in principle, is to have some shim to call display_error() rather than printing the current exception and backtrace separately. If display_error doesn't exist or fails, then the fallback path of shown_err == 0 would be taken.

@vchuravy vchuravy merged commit 0b2c208 into master Oct 29, 2020
@vchuravy vchuravy deleted the vc/backtraces branch October 29, 2020 14:51
KristofferC pushed a commit that referenced this pull request Nov 2, 2020
insert backtrace printing into user-facing JL_CATCH
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants