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

Lwt_unix.with_async_switch => longjmp causes uninitialized stack frame => segfault #184

Closed
didier-wenzek opened this issue Sep 10, 2015 · 5 comments

Comments

@didier-wenzek
Copy link

Since I switched to ocaml 4.02.3 and lwt 2.5.0,
this short program leads to a segfault:

open Lwt
let main () = Lwt_main.run (Lwt_io.printf "Hello world!\n%!")
let () = Lwt_unix.with_async_switch main
$ ocamlbuild -use-ocamlfind -pkgs lwt,lwt.unix hello.native
$ ./hello.native 
*** longjmp causes uninitialized stack frame ***: ./hello.native terminated
Segmentation fault (core dumped)

This can be fixed using with_async_detach.
Since with_async_switch is documented as experimental this may be ok.
But, what is strange is that it was working with ocaml 4.02.1 and lwt 2.4.8.

The back trace is :

#0  0xb6a71788 in ?? () from /lib/i386-linux-gnu/libgcc_s.so.1
#1  0xb6a726d4 in _Unwind_Backtrace () from /lib/i386-linux-gnu/libgcc_s.so.1
#2  0xb760cf17 in __GI___backtrace (array=0xbff16230, size=64) at ../sysdeps/i386/backtrace.c:127
#3  0xb7572fe0 in __libc_message (do_abort=2, fmt=0xb766c247 "*** %s ***: %s terminated\n") at ../sysdeps/unix/sysv/linux/libc_fatal.c:180
#4  0xb760cce5 in __GI___fortify_fail (msg=0xb766c206 "longjmp causes uninitialized stack frame") at fortify_fail.c:32
#5  0xb760cc3a in ____longjmp_chk () at ../sysdeps/unix/sysv/linux/i386/____longjmp_chk.S:76
#6  0xb760cbab in __longjmp_chk (env=0x871da60, val=1) at ../setjmp/longjmp.c:40
#7  0x080a8390 in lwt_unix_start_job (val_job=-1219515704, val_async_method=5) at src/unix/lwt_unix_stubs.c:1422
#8  0x0805453a in camlLwt_unix__run_job_aux_1150 () at src/unix/lwt_unix.ml:189
#9  0x0805dbf1 in camlLwt_io__perform_io_1167 () at src/unix/lwt_io.ml:211
#10 0x0805dd59 in camlLwt_io__flush_total_1181 () at src/unix/lwt_io.ml:256
#11 0x0806b8ea in camlLwt__catch_1469 () at src/core/lwt.ml:686
#12 0x0805bbf5 in camlLwt_io__fun_2315 () at src/unix/lwt_io.ml:293
#13 0x08068708 in camlLwt__fun_2114 () at src/core/lwt.ml:653
#14 0x0806a118 in camlLwt__run_waiters_rec_1152 () at src/core/lwt.ml:201
#15 0x0806a3c4 in camlLwt__safe_run_waiters_1196 () at src/core/lwt.ml:299
#16 0x080679c3 in camlLwt_sequence__loop_1066 () at src/core/lwt_sequence.ml:149
#17 0x08051ee0 in camlLwt_main__run_1018 () at src/unix/lwt_main.ml:33
#18 0x0806d22c in camlLwt__with_value_1709 () at src/core/lwt.ml:1169
#19 0x0804efc2 in camlHello__entry ()
#20 0x0804bd64 in caml_program ()
#21 0x080c40b9 in caml_start_program ()
#22 0x080b335f in caml_main ()
#23 0x080b33a4 in main ()
@aantron
Copy link
Collaborator

aantron commented Jul 2, 2016

Hm, I'm unable to reproduce this on my OS X system, with OCaml 4.02.3 and both Lwt 2.5.0 and master. I don't (yet) see any potentially relevant changes between 2.4.8 and 2.5.0 that could have caused this.

If still having this issue, and willing to debug, please say which system you are running on, and whether/how you can reproduce it today.

@didier-wenzek
Copy link
Author

I still have the issue with OCaml 4.03.0, lwt 2.5.2 on a 32-bit system with Ubuntu 14.04.4.

I will take time to check on a 64bit system.

@didier-wenzek
Copy link
Author

I still have the issue on a 64bit Intel system with Ubuntu 14.04.

This is fine with OCaml 4.02.1 and lwt.2.5.2.
But not with 4.03.0 and lwt 2.5.2 (die saying "longjmp causes uninitialized stack frame")
In both cases, the version of lwt is the same.

@aantron
Copy link
Collaborator

aantron commented Jul 4, 2016

Thanks, was able to reproduce this (Ubuntu 14.04 x86_64, Lwt 2.5.2, OCaml 4.03.0).

@aantron
Copy link
Collaborator

aantron commented Aug 3, 2019

Lwt_unix.with_async_switch will be deprecated by #572, and probably removed in Lwt 5.0.0.

@aantron aantron closed this as completed Aug 3, 2019
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

No branches or pull requests

2 participants