Thread: [Cppcms-users] Segmentation fault
Brought to you by:
artyom-beilis
From: Mario P. <mp...@us...> - 2010-10-20 17:40:25
|
Hello, I'm starting to use CppCMS ("cppcms-0.99.3.tar.bz2" downloaded from SourceForge), and noticed that when generating very long responses, the executable ends with a segfault. I am using the built-in server, and I reduced the code to the following: ______________________________________________________________________________ /* bench.cpp */ #include <cppcms/application.h> #include <cppcms/applications_pool.h> #include <cppcms/service.h> #include <cppcms/http_response.h> #include <iostream> class bench : public cppcms::application { public: bench(cppcms::service &srv) : cppcms::application(srv) { } virtual void main(std::string url) { for (int i=0; i < 100000; ++i) { response().out() << i << "\n"; } }//main };//class bench int main(int argc, char *argv[]) { try { cppcms::service srv(argc, argv); srv.applications_pool().mount(cppcms::applications_factory<bench>()); srv.run(); } catch (const std::exception &e) { std::cerr << e.what() << std::endl; } return 0; }//main ______________________________________________________________________________ ______________________________________________________________________________ /* config.js */ { "service": { "api": "http", "port": 8080, }, "http": { "script_names": [ "/bench" ], }, } ______________________________________________________________________________ I start the application: $ ./bench -c config.js Then, I use "curl" to make a request: $ curl http://localhost:8080/bench And the application ("bench") terminates with a segmentation fault. A backtrace shows that the last statement that is executed is the line 476 of file "cgi_api.cpp" ('write_some()' in function 'connection::write()'), but so far I have not gotten more information. Can anyone else reproduce the problem? Can be solved if I use the latest version in SVN? (I'll try to test soon with the latest version of the code). Thank you for creating something as awesome as CppCMS. Regards, Mario |
From: Artyom <art...@ya...> - 2010-10-20 21:21:14
|
I hadn't reproduced the crash bug, but there is other but that seems to be related, I'm working on it that may cause the crash. Also can you send me the backtrace of the crash? You can do it with gdb this way: Compile with "-g" switch and then in gdb > r -c config.js --- Observer Crash > bt ..... this is trace Artyom ----- Original Message ---- > From: Mario Palomo <mp...@us...> > To: cpp...@li... > Sent: Wed, October 20, 2010 7:30:07 PM > Subject: [Cppcms-users] Segmentation fault > > Hello, > > I'm starting to use CppCMS ("cppcms-0.99.3.tar.bz2" downloaded from > SourceForge), and noticed that when generating very long responses, the > executable ends with a segfault. I am using the built-in server, and I reduced > > the code to the following: > > ______________________________________________________________________________ > /* > bench.cpp > */ > #include <cppcms/application.h> > #include <cppcms/applications_pool.h> > #include <cppcms/service.h> > #include <cppcms/http_response.h> > #include <iostream> > > class bench : public cppcms::application > { > public: > bench(cppcms::service &srv) : cppcms::application(srv) { } > > virtual void main(std::string url) > { > for (int i=0; i < 100000; ++i) { > response().out() << i << "\n"; > } > }//main > };//class bench > > int main(int argc, char *argv[]) > { > try { > cppcms::service srv(argc, argv); > srv.applications_pool().mount(cppcms::applications_factory<bench>()); > srv.run(); > } > catch (const std::exception &e) { > std::cerr << e.what() << std::endl; > } > > return 0; > }//main > ______________________________________________________________________________ > > ______________________________________________________________________________ > /* > config.js > */ > { > "service": { > "api": "http", > "port": 8080, > }, > "http": { > "script_names": [ "/bench" ], > }, > } > ______________________________________________________________________________ > > > I start the application: > > $ ./bench -c config.js > > Then, I use "curl" to make a request: > > $ curl http://localhost:8080/bench > > And the application ("bench") terminates with a segmentation fault. > > A backtrace shows that the last statement that is executed is the line 476 of > file "cgi_api.cpp" ('write_some()' in function 'connection::write()'), but so > far I have not gotten more information. > > Can anyone else reproduce the problem? Can be solved if I use the latest > version in SVN? (I'll try to test soon with the latest version of the code). > > Thank you for creating something as awesome as CppCMS. Regards, > > Mario > > > > ------------------------------------------------------------------------------ > Nokia and AT&T present the 2010 Calling All Innovators-North America contest > Create new apps & games for the Nokia N8 for consumers in U.S. and Canada > $10 million total in prizes - $4M cash, 500 devices, nearly $6M in marketing > Develop with Nokia Qt SDK, Web Runtime, or Java and Publish to Ovi Store > http://p.sf.net/sfu/nokia-dev2dev > _______________________________________________ > Cppcms-users mailing list > Cpp...@li... > https://lists.sourceforge.net/lists/listinfo/cppcms-users > |
From: Mario P. <mp...@us...> - 2010-10-21 07:53:15
|
2010-10-20 23:21 +0200, Artyom wrote: > I hadn't reproduced the crash bug, but there is other but that seems to be > related, > I'm working on it that may cause the crash. > > Also can you send me the backtrace of the crash? > > You can do it with gdb this way: > Compile with "-g" switch and then in gdb > >> r -c config.js > --- Observer Crash >> bt > ..... this is trace > > > Artyom > Here it is: $ g++ -g -o bench bench.cpp -Wall -I/home/mario/cppcms/include -L/home/mario/cppcms/lib -lcppcms -lbooster $ LD_LIBRARY_PATH=/home/mario/cppcms/lib gdb ./bench GNU gdb (GDB) 7.2-debian Copyright (C) 2010 Free Software Foundation, Inc. License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html> This is free software: you are free to change and redistribute it. There is NO WARRANTY, to the extent permitted by law. Type "show copying" and "show warranty" for details. This GDB was configured as "x86_64-linux-gnu". For bug reporting instructions, please see: <http://www.gnu.org/software/gdb/bugs/>... Reading symbols from /home/mario/cppcms/bench...done. (gdb) r -c config.js Starting program: /home/mario/cppcms/bench -c config.js [Thread debugging using libthread_db enabled] [New Thread 0x7ffff45a1710 (LWP 2739)] [New Thread 0x7ffff3da0710 (LWP 2740)] [New Thread 0x7ffff359f710 (LWP 2741)] [New Thread 0x7ffff2d9e710 (LWP 2742)] [New Thread 0x7ffff259d710 (LWP 2743)] Program received signal SIGSEGV, Segmentation fault. [Switching to Thread 0x7ffff359f710 (LWP 2741)] 0x00007ffff7a88708 in cppcms::impl::cgi::connection::write (this=0x648c60, data=<value optimized out>, n=16384) at /home/mario/isla/cppcms-0.99.3/src/cgi_api.cpp:476 476 size_t d=write_some(p,n); (gdb) bt #0 0x00007ffff7a88708 in cppcms::impl::cgi::connection::write (this=0x648c60, data=<value optimized out>, n=16384) at /home/mario/isla/cppcms-0.99.3/src/cgi_api.cpp:476 #1 0x00007ffff7a99423 in write (this=0x649610) at /home/mario/isla/cppcms-0.99.3/src/http_response.cpp:83 #2 write<cppcms::http::<unnamed>::output_device> (this=0x649610) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/write.hpp:121 #3 write<cppcms::http::<unnamed>::output_device> (this=0x649610) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/write.hpp:53 #4 write<cppcms::http::<unnamed>::output_device, cppcms_boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > (this=0x649610) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/detail/adapter/concept_adapter.hpp:188 #5 write<cppcms_boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > (this=0x649610) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/detail/adapter/concept_adapter.hpp:82 #6 cppcms_boost::iostreams::detail::indirect_streambuf<cppcms::http::<unnamed>::output_device, std::char_traits<char>, std::allocator<char>, cppcms_boost::iostreams::output>::sync_impl(void) (this=0x649610) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/detail/streambuf/indirect_streambuf.hpp:392 #7 0x00007ffff7a99509 in cppcms_boost::iostreams::detail::indirect_streambuf<cppcms::http::<unnamed>::output_device, std::char_traits<char>, std::allocator<char>, cppcms_boost::iostreams::output>::sync(void) (this=0x648c60) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/detail/streambuf/indirect_streambuf.hpp:312 #8 0x00007ffff7a993aa in cppcms_boost::iostreams::detail::indirect_streambuf<cppcms::http::<unnamed>::output_device, std::char_traits<char>, std::allocator<char>, cppcms_boost::iostreams::output>::close_impl(std::_Ios_Openmode) (this=0x649610, which=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/detail/streambuf/indirect_streambuf.hpp:375 #9 0x00007ffff7a9ff35 in close (op=..., c0=...) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/detail/streambuf/linked_streambuf.hpp:82 #10 operator() (op=..., c0=...) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/detail/functional.hpp:116 #11 cppcms_boost::iostreams::detail::execute_all<cppcms_boost::iostreams::detail::member_close_operation<cppcms_boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >, cppcms_boost::iostreams::detail::member_close_operation<cppcms_boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > > > (op=..., c0=...) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/preprocessor/iteration/detail/local.hpp:37 #12 0x00007ffff7a99725 in execute_all<cppcms_boost::iostreams::detail::member_close_operation<cppcms_boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >, cppcms_boost::iostreams::detail::member_close_operation<cppcms_boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >, cppcms_boost::iostreams::detail::reset_operation<cppcms_boost::iostreams::detail::optional<cppcms_boost::iostreams::detail::concept_adapter<cppcms::http::<unnamed>::output_device> > > > (op=..., c0=..., c1=..., c2=...) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/preprocessor/iteration/detail/local.hpp:40 #13 cppcms_boost::iostreams::detail::execute_all<cppcms_boost::iostreams::detail::member_close_operation<cppcms_boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >, cppcms_boost::iostreams::detail::member_close_operation<cppcms_boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >, cppcms_boost::iostreams::detail::reset_operat---Type <return> to continue, or q <return> to quit--- ion<cppcms_boost::iostreams::detail::optional<cppcms_boost::iostreams::detail::concept_adapter<cppcms::http::<unnamed>::output_device> > >, cppcms_boost::iostreams::detail::clear_flags_operation<int> >(cppcms_boost::iostreams::detail::member_close_operation<cppcms_boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >, cppcms_boost::iostreams::detail::member_close_operation<cppcms_boost::iostreams::detail::linked_streambuf<char, std::char_traits<char> > >, cppcms_boost::iostreams::detail::reset_operation<cppcms_boost::iostreams::detail::optional<cppcms_boost::iostreams::detail::concept_adapter<cppcms::http::<unnamed>::output_device> > >, cppcms_boost::iostreams::detail::clear_flags_operation<int>) (op=..., c0=..., c1=..., c2=...) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/preprocessor/iteration/detail/local.hpp:43 #14 0x00007ffff7a99ad1 in close (this=0x648c60, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/detail/streambuf/indirect_streambuf.hpp:202 #15 cppcms_boost::iostreams::stream_buffer<cppcms::http::<unnamed>::output_device, std::char_traits<char>, std::allocator<char>, cppcms_boost::iostreams::output>::~stream_buffer(void) ( this=0x648c60, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/stream_buffer.hpp:90 #16 0x00007ffff7aa3504 in ~base_from_member (this=<value optimized out>, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/utility/base_from_member.hpp:67 #17 ~stream_base (this=<value optimized out>, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/stream.hpp:77 #18 ~stream (this=<value optimized out>, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/iostreams/stream.hpp:112 #19 ~_data (this=<value optimized out>, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/src/http_response.cpp:88 #20 booster::hold_ptr<cppcms::http::response::_data>::~hold_ptr (this=<value optimized out>, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/booster/booster/hold_ptr.h:27 #21 0x00007ffff7a9a1c9 in cppcms::http::response::~response (this=0x648c60, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/src/http_response.cpp:124 #22 0x00007ffff7aa6e69 in ~auto_ptr (this=0x6216a0, __in_chrg=<value optimized out>) at /usr/include/c++/4.4/backward/auto_ptr.h:168 #23 ~_data (this=0x6216a0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/src/http_context.cpp:46 #24 ~hold_ptr (this=0x6216a0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/booster/booster/hold_ptr.h:27 #25 cppcms::http::context::~context (this=0x6216a0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/src/http_context.cpp:208 #26 0x00007ffff7aa90e2 in checked_delete<cppcms::http::context> (this=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/booster/booster/checked_delete.h:30 #27 booster::detail::sp_counted_impl_p<cppcms::http::context>::dispose (this=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/booster/booster/smart_ptr/sp_counted_impl.h:51 #28 0x00007ffff775ba56 in booster::detail::sp_counted_base::release (this=0x611140) at /home/mario/isla/cppcms-0.99.3/booster/lib/smart_ptr/src/sp_counted_base.cpp:268 #29 0x00007ffff7aad8a0 in cppcms::application::recycle (this=0x648c60) at /home/mario/isla/cppcms-0.99.3/src/application.cpp:214 #30 0x00007ffff7aad92b in booster::intrusive_ptr_release (app=0x650500) at /home/mario/isla/cppcms-0.99.3/src/application.cpp:240 ---Type <return> to continue, or q <return> to quit--- #31 0x00007ffff7aa8be5 in ~intrusive_ptr (this=0x6505f0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/booster/booster/intrusive_ptr.h:68 #32 ~value (this=0x6505f0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/bind/bind.hpp:113 #33 ~storage1 (this=0x6505f0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/bind/storage.hpp:41 #34 ~storage2 (this=0x6505f0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/bind/storage.hpp:77 #35 ~storage3 (this=0x6505f0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/bind/storage.hpp:126 #36 ~list3 (this=0x6505f0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/bind/bind.hpp:346 #37 ~bind_t (this=0x6505f0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/cppcms_boost/cppcms_boost/bind/bind.hpp:854 #38 callable_impl<void, cppcms_boost::_bi::bind_t<void, void (*)(booster::intrusive_ptr<cppcms::application>, std::basic_string<char, std::char_traits<char>, std::allocator<char> >, bool), cppcms_boost::_bi::list3<cppcms_boost::_bi::value<booster::intrusive_ptr<cppcms::application> >, cppcms_boost::_bi::value<std::basic_string<char, std::char_traits<char>, std::allocator<char> > >, cppcms_boost::_bi::value<bool> > > >::~callable_impl (this=0x6505f0, __in_chrg=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/booster/booster/function.h:163 #39 0x00007ffff7aaa229 in ~clone_ptr (this=0x6084e0) at /home/mario/isla/cppcms-0.99.3/booster/booster/clone_ptr.h:42 #40 ~function (this=0x6084e0) at /home/mario/isla/cppcms-0.99.3/booster/booster/function.h:16 #41 cppcms::impl::thread_pool::worker (this=0x6084e0) at /home/mario/isla/cppcms-0.99.3/src/thread_pool.cpp:110 #42 0x00007ffff774b29c in operator() (p=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/booster/./booster/function.h:163 #43 booster::booster_thread_func (p=<value optimized out>) at /home/mario/isla/cppcms-0.99.3/booster/lib/thread/src/thread.cpp:33 #44 0x00007ffff63418ba in start_thread (arg=<value optimized out>) at pthread_create.c:300 #45 0x00007ffff6cb902d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112 #46 0x0000000000000000 in ?? () (gdb) Best regards, Mario |
From: Mario P. <mp...@us...> - 2010-10-21 15:24:44
|
2010-10-20 19:30 +0200, Mario Palomo wrote: > Hello, > > I'm starting to use CppCMS ("cppcms-0.99.3.tar.bz2" downloaded from > SourceForge), and noticed that when generating very long responses, the > executable ends with a segfault. I am using the built-in server, and I reduced > the code to the following: > [...] If it helps, I have written an equivalent asynchronous application, and the error does NOT occur: ______________________________________________________________________________ /* bench.cpp */ #include <cppcms/application.h> #include <cppcms/applications_pool.h> #include <cppcms/service.h> #include <cppcms/http_response.h> #include <iostream> class bench : public cppcms::application { public: bench(cppcms::service &srv) : cppcms::application(srv) { } virtual void main(std::string url) { for (int i=0; i < 100000; ++i) { response().out() << i << "\n"; } release_context()->async_complete_response(); }//main };//class bench int main(int argc, char *argv[]) { try { cppcms::service srv(argc, argv); booster::intrusive_ptr<bench> app = new bench(srv); srv.applications_pool().mount(app); srv.run(); } catch (const std::exception &e) { std::cerr << e.what() << std::endl; } return 0; }//main ______________________________________________________________________________ ______________________________________________________________________________ //config.js { "service": { "api": "http", "port": 8080, }, "http": { "script_names": [ "/bench" ], }, } ______________________________________________________________________________ When do you recommend using an application of one type or the other? Best regards, Mario |
From: Artyom <art...@ya...> - 2010-10-21 15:48:23
|
> > > > I'm starting to use CppCMS ("cppcms-0.99.3.tar.bz2" downloaded from > > SourceForge), and noticed that when generating very long responses, the > > executable ends with a segfault. I am using the built-in server, and I >reduced > > the code to the following: > > > [...] > > If it helps, I have written an equivalent asynchronous application, and the > error does NOT occur: > > [...] > > When do you recommend using an application of one type or the other? > > Best regards, > > Mario > No, it is just a bug I had already reproduced and I have a direction to fix it. What happens that the connection socket incorrectly remains in non-blocking mode causing a fault when getting to EWOULDBLOCK in synchronous mode, of course this does not happen in async mode as EWOULDBLOCK is expected. It is just little bit more complex then "few lines of fix" I'll fix this bug ASAP and I'll let you know, hopefully today or tomorrow it would be done. Artyom |
From: Artyom <art...@ya...> - 2010-10-23 14:31:14
|
Hello, This bug should be fixed in svn trunk, in changeset 1486. Please try the version from SVN. The official version 0.99.4 will be released soon with this fix. Artyom > 2010-10-20 19:30 +0200, Mario Palomo wrote: > > Hello, > > > > I'm starting to use CppCMS ("cppcms-0.99.3.tar.bz2" downloaded from > > SourceForge), and noticed that when generating very long responses, the > > executable ends with a segfault. I am using the built-in server, and I >reduced > > the code to the following: > > > [...] > > If it helps, I have written an equivalent asynchronous application, and the > error does NOT occur: > |
From: Mario P. <mp...@us...> - 2010-10-24 14:51:02
|
2010-10-23 16:31 +0200, Artyom wrote: > Hello, > > This bug should be fixed in svn trunk, in changeset 1486. > Please try the version from SVN. > The official version 0.99.4 will be released soon with this fix. > > Artyom > I tried it and now it works perfectly. Thanks a lot! In short I can have time to build a Debian package of CppCMS. Do you want I send you a patch to integrate into the CppCMS repository?. Is there already code to generate Debian packages written by somebody? Mario |
From: Artyom <art...@ya...> - 2010-10-25 09:03:34
|
> > In short I can have time to build a Debian package of CppCMS. Do you want I > send you a patch to integrate into the CppCMS repository?. You are welcome, it would be very nice. Take a look on this link: http://art-blog.no-ip.info/wikipp/en/page/contrib > Is there already code to generate Debian packages written by somebody? Not that I'm aware of. Artyom |