{"action":"created","issue":{"url":"https://api.github.com/repos/SWI-Prolog/packages-http/issues/43","labels_url":"https://api.github.com/repos/SWI-Prolog/packages-http/issues/43/labels{/name}","comments_url":"https://api.github.com/repos/SWI-Prolog/packages-http/issues/43/comments","events_url":"https://api.github.com/repos/SWI-Prolog/packages-http/issues/43/events","html_url":"https://github.com/SWI-Prolog/packages-http/issues/43","id":128357307,"number":43,"title":"HTTP server crashes with fatal signal 11: C-stack trace labeled \"crash\"","user":{"login":"triska","id":7482140,"avatar_url":"https://avatars.githubusercontent.com/u/7482140?v=3","gravatar_id":"","url":"https://api.github.com/users/triska","html_url":"https://github.com/triska","followers_url":"https://api.github.com/users/triska/followers","following_url":"https://api.github.com/users/triska/following{/other_user}","gists_url":"https://api.github.com/users/triska/gists{/gist_id}","starred_url":"https://api.github.com/users/triska/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/triska/subscriptions","organizations_url":"https://api.github.com/users/triska/orgs","repos_url":"https://api.github.com/users/triska/repos","events_url":"https://api.github.com/users/triska/events{/privacy}","received_events_url":"https://api.github.com/users/triska/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":1,"created_at":"2016-01-23T22:47:36Z","updated_at":"2016-01-24T09:29:45Z","closed_at":null,"body":"Let `server.pl` consist of:\r\n\r\n<pre>\r\n:- use_module(library(http/thread_httpd)).\r\n:- use_module(library(http/http_dispatch)).\r\n:- use_module(library(http/http_unix_daemon)).\r\n\r\n:- initialization http_daemon.\r\n\r\n:- http_handler(/, handle_request, []).\r\n\r\nhandle_request(_Request) :-\r\n    format(\"Content-type: text/plain~n~n\"),\r\n    format(\"hello!!\").\r\n</pre>\r\n\r\nStart the server with:\r\n\r\n    $ swipl server.pl --interactive --port=3030\r\n\r\nLet `test_server.tcl` consist of:\r\n\r\n<pre>\r\nset i 0\r\nwhile {true} {\r\n    if {$i % 100 == 0} { puts \"$i.\"}\r\n    set s [socket localhost 3030]\r\n    puts $s \"GET /\"\r\n    set i [expr {$i + 1}]\r\n}\r\n</pre>\r\n\r\nand run this Tcl script with:\r\n\r\n    $ tclsh test_server.tcl\r\n\r\nOn OSX 10.10.1, I get the following output from the test script:\r\n\r\n<pre>\r\n$ tclsh test_server.tcl\r\n0.\r\n100.\r\n200.\r\n...\r\n2500.\r\ncouldn't open socket: nodename nor servname provided, or not known\r\n</pre>\r\n\r\nand the SWI-Prolog HTTP server crashes with:\r\n\r\n<pre>\r\n% Started server at http://localhost:3030/\r\n% Started server at port 3030\r\nWelcome to SWI-Prolog (Multi-threaded, 64 bits, Version 7.3.14-62-g18f1547-DIRTY)\r\nCopyright (c) 1990-2015 University of Amsterdam, VU Amsterdam\r\nSWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software,\r\nand you are welcome to redistribute it under certain conditions.\r\nPlease visit http://www.swi-prolog.org for details.\r\n\r\nFor help, use ?- help(Topic). or ?- apropos(Word).\r\n\r\n?- \r\n<b>SWI-Prolog [thread 3 (httpd@3030_2) at Sat Jan 23 23:38:32 2016]: received fatal signal 11 (segv)\r\nC-stack trace labeled \"crash\":</b>\r\n  [0] /usr/local/lib/swipl-7.1.27/lib/x86_64-darwin14.0.0/libswipl.dylib(save_backtrace+0xb9) [0x104a60d69]\r\n  [1] /usr/local/lib/swipl-7.1.27/lib/x86_64-darwin14.0.0/libswipl.dylib(crashHandler+0xa8) [0x104a61348]\r\n  [2] /usr/local/lib/swipl-7.1.27/lib/x86_64-darwin14.0.0/libswipl.dylib(dispatch_signal+0x2d3) [0x104a09333]\r\n  [3] /usr/lib/system/libsystem_platform.dylib(_sigtramp+0x1a) [0x7fff91c49f1a]\r\n  [5] /usr/local/lib/swipl-7.1.27/lib/x86_64-darwin14.0.0/libswipl.dylib(Sgetcode+0x260) [0x104a4e520]\r\n  [6] /usr/local/lib/swipl-7.1.27/lib/x86_64-darwin14.0.0/readutil.dylib(read_line_to_codes3+0x7c) [0x104b30b0c]\r\n  [7] /usr/local/lib/swipl-7.1.27/lib/x86_64-darwin14.0.0/libswipl.dylib(PL_next_solution+0x80c2) [0x10499dfd2]\r\n  [8] /usr/local/lib/swipl-7.1.27/lib/x86_64-darwin14.0.0/libswipl.dylib(callProlog+0x151) [0x1049ebcc1]\r\n  [9] /usr/local/lib/swipl-7.1.27/lib/x86_64-darwin14.0.0/libswipl.dylib(start_thread+0x140) [0x104a1e810]\r\n  [10] /usr/lib/system/libsystem_pthread.dylib(_pthread_body+0x83) [0x7fff88bb72fc]\r\n  [11] /usr/lib/system/libsystem_pthread.dylib(_pthread_body+0x0) [0x7fff88bb7279]\r\n  [12] /usr/lib/system/libsystem_pthread.dylib(thread_start+0xd) [0x7fff88bb54b1]\r\n</pre>\r\n\r\nOn Debian 8.2, the test script `test_server.tcl` runs seemingly without problems, but as soon as I interrupt the script with `Ctrl+C`, the SWI-Prolog HTTP server also crashes on Debian, and its output is:\r\n\r\n<pre>\r\n?- \r\nSWI-Prolog [thread 4 (httpd@3030_3) at Sat Jan 23 23:45:32 2016]: received fatal signal 11 (segv)\r\n\r\nSWI-Prolog [thread 3 (httpd@3030_2) at Sat Jan 23 23:45:32 2016]: received fatal signal 11 (segv)\r\n\r\nSWI-Prolog [thread 5 (httpd@3030_4) at Sat Jan 23 23:45:32 2016]: received fatal signal 11 (segv)\r\nC-stack trace labeled \"crash\":\r\nC-stack trace labeled \"crash\":\r\n\r\nSWI-Prolog [thread 6 (httpd@3030_5) at Sat Jan 23 23:45:32 2016]: received fatal signal 11 (segv)\r\n\r\nSWI-Prolog [thread 2 (httpd@3030_1) at Sat Jan 23 23:45:32 2016]: received fatal signal 11 (segv)\r\nC-stack trace labeled \"crash\":\r\nC-stack trace labeled \"crash\":\r\nC-stack trace labeled \"crash\":\r\n  [0] save_backtrace() at :? [0x7f5c64ef183a]\r\n  [0] save_backtrace() at :? [0x7f5c64ef183a]\r\n  [0] save_backtrace() at :? [0x7f5c64ef183a]\r\n  [0] save_backtrace() at :? [0x7f5c64ef183a]\r\n  [0] save_backtrace() at :? [0x7f5c64ef183a]\r\n  [1] crashHandler() at pl-cstack.c:? [0x7f5c64ef1a04]\r\n  [1] crashHandler() at pl-cstack.c:? [0x7f5c64ef1a04]\r\n  [1] crashHandler() at pl-cstack.c:? [0x7f5c64ef1a04]\r\n  [1] crashHandler() at pl-cstack.c:? [0x7f5c64ef1a04]\r\n  [1] crashHandler() at pl-cstack.c:? [0x7f5c64ef1a04]\r\n  [2] dispatch_signal() at pl-setup.c:? [0x7f5c64ea162b]\r\n  [2] dispatch_signal() at pl-setup.c:? [0x7f5c64ea162b]\r\n  [2] dispatch_signal() at pl-setup.c:? [0x7f5c64ea162b]\r\n  [2] dispatch_signal() at pl-setup.c:? [0x7f5c64ea162b]\r\n  [3] __restore_rt() at ??:? [0x7f5c64c0b8d0]\r\n  [3] __restore_rt() at ??:? [0x7f5c64c0b8d0]\r\n  [3] __restore_rt() at ??:? [0x7f5c64c0b8d0]\r\n  [2] dispatch_signal() at pl-setup.c:? [0x7f5c64ea162b]\r\n  [3] __restore_rt() at ??:? [0x7f5c64c0b8d0]\r\n  [4] S__fillbuf() at ??:? [0x7f5c64ee361d]\r\n  [4] S__fillbuf() at ??:? [0x7f5c64ee361d]\r\n  [4] S__fillbuf() at ??:? [0x7f5c64ee361d]\r\n  [3] __restore_rt() at ??:? [0x7f5c64c0b8d0]\r\n  [5] Sgetcode() at ??:? [0x7f5c64ee40d0]\r\n  [4] S__fillbuf() at ??:? [0x7f5c64ee361d]\r\n  [5] Sgetcode() at ??:? [0x7f5c64ee40d0]\r\n  [4] S__fillbuf() at ??:? [0x7f5c64ee361d]\r\n  [5] Sgetcode() at ??:? [0x7f5c64ee40d0]\r\n  [6] read_line_to_codes3() at readutil.c:? [0x7f5c63645c67]\r\n  [6] read_line_to_codes3() at readutil.c:? [0x7f5c63645c67]\r\n  [5] Sgetcode() at ??:? [0x7f5c64ee40d0]\r\n  [6] read_line_to_codes3() at readutil.c:? [0x7f5c63645c67]\r\n  [7] PL_next_solution() at ??:? [0x7f5c64e55a65]\r\n  [7] PL_next_solution() at ??:? [0x7f5c64e55a65]\r\n  [5] Sgetcode() at ??:? [0x7f5c64ee40d0]\r\n  [8] callProlog() at :? [0x7f5c64e8ada9]\r\n  [6] read_line_to_codes3() at readutil.c:? [0x7f5c63645c67]\r\n  [8] callProlog() at :? [0x7f5c64e8ada9]\r\n  [7] PL_next_solution() at ??:? [0x7f5c64e55a65]\r\n  [6] read_line_to_codes3() at readutil.c:? [0x7f5c63645c67]\r\n  [7] PL_next_solution() at ??:? [0x7f5c64e55a65]\r\n  [8] callProlog() at :? [0x7f5c64e8ada9]\r\n  [9] start_thread() at pl-thread.c:? [0x7f5c64eb7fb2]\r\n  [9] start_thread() at pl-thread.c:? [0x7f5c64eb7fb2]\r\n  [8] callProlog() at :? [0x7f5c64e8ada9]\r\n  [7] PL_next_solution() at ??:? [0x7f5c64e55a65]\r\n  [9] start_thread() at pl-thread.c:? [0x7f5c64eb7fb2]\r\n  [10] start_thread() at ??:? [0x7f5c64c040a4]\r\n  [10] start_thread() at ??:? [0x7f5c64c040a4]\r\n  [8] callProlog() at :? [0x7f5c64e8ada9]\r\n  [9] start_thread() at pl-thread.c:? [0x7f5c64eb7fb2]\r\n  [10] start_thread() at ??:? [0x7f5c64c040a4]\r\n  [9] start_thread() at pl-thread.c:? [0x7f5c64eb7fb2]\r\n  [10] start_thread() at ??:? [0x7f5c64c040a4]\r\n  [11] clone() at ??:? [0x7f5c6493904d]\r\n</pre>\r\n"},"comment":{"url":"https://api.github.com/repos/SWI-Prolog/packages-http/issues/comments/174271814","html_url":"https://github.com/SWI-Prolog/packages-http/issues/43#issuecomment-174271814","issue_url":"https://api.github.com/repos/SWI-Prolog/packages-http/issues/43","id":174271814,"user":{"login":"JanWielemaker","id":3071146,"avatar_url":"https://avatars.githubusercontent.com/u/3071146?v=3","gravatar_id":"","url":"https://api.github.com/users/JanWielemaker","html_url":"https://github.com/JanWielemaker","followers_url":"https://api.github.com/users/JanWielemaker/followers","following_url":"https://api.github.com/users/JanWielemaker/following{/other_user}","gists_url":"https://api.github.com/users/JanWielemaker/gists{/gist_id}","starred_url":"https://api.github.com/users/JanWielemaker/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/JanWielemaker/subscriptions","organizations_url":"https://api.github.com/users/JanWielemaker/orgs","repos_url":"https://api.github.com/users/JanWielemaker/repos","events_url":"https://api.github.com/users/JanWielemaker/events{/privacy}","received_events_url":"https://api.github.com/users/JanWielemaker/received_events","type":"User","site_admin":false},"created_at":"2016-01-24T09:29:45Z","updated_at":"2016-01-24T09:29:45Z","body":"You do not read and close the input.   As a result, you'll run out of open files.  What and where depends a lot on timing.  In my case it is TCL running out first.  Look like in your case it is Prolog running out first and probably somewhere ignores an error.  You might get an idea after compiling for debugging and running under gdb."}}