{"action":"created","issue":{"url":"https://api.github.com/repos/libbitcoin/libbitcoin-server/issues/36","labels_url":"https://api.github.com/repos/libbitcoin/libbitcoin-server/issues/36/labels{/name}","comments_url":"https://api.github.com/repos/libbitcoin/libbitcoin-server/issues/36/comments","events_url":"https://api.github.com/repos/libbitcoin/libbitcoin-server/issues/36/events","html_url":"https://github.com/libbitcoin/libbitcoin-server/issues/36","id":56611435,"number":36,"title":"Segfault on OSX 10.10 and Linux during sync (both Clang).","user":{"login":"evoskuil","id":1369335,"avatar_url":"https://avatars.githubusercontent.com/u/1369335?v=3","gravatar_id":"","url":"https://api.github.com/users/evoskuil","html_url":"https://github.com/evoskuil","followers_url":"https://api.github.com/users/evoskuil/followers","following_url":"https://api.github.com/users/evoskuil/following{/other_user}","gists_url":"https://api.github.com/users/evoskuil/gists{/gist_id}","starred_url":"https://api.github.com/users/evoskuil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evoskuil/subscriptions","organizations_url":"https://api.github.com/users/evoskuil/orgs","repos_url":"https://api.github.com/users/evoskuil/repos","events_url":"https://api.github.com/users/evoskuil/events{/privacy}","received_events_url":"https://api.github.com/users/evoskuil/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":{"url":"https://api.github.com/repos/libbitcoin/libbitcoin-server/milestones/2","labels_url":"https://api.github.com/repos/libbitcoin/libbitcoin-server/milestones/2/labels","id":966495,"number":2,"title":"2.1","description":null,"creator":{"login":"evoskuil","id":1369335,"avatar_url":"https://avatars.githubusercontent.com/u/1369335?v=3","gravatar_id":"","url":"https://api.github.com/users/evoskuil","html_url":"https://github.com/evoskuil","followers_url":"https://api.github.com/users/evoskuil/followers","following_url":"https://api.github.com/users/evoskuil/following{/other_user}","gists_url":"https://api.github.com/users/evoskuil/gists{/gist_id}","starred_url":"https://api.github.com/users/evoskuil/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/evoskuil/subscriptions","organizations_url":"https://api.github.com/users/evoskuil/orgs","repos_url":"https://api.github.com/users/evoskuil/repos","events_url":"https://api.github.com/users/evoskuil/events{/privacy}","received_events_url":"https://api.github.com/users/evoskuil/received_events","type":"User","site_admin":false},"open_issues":5,"closed_issues":0,"state":"open","created_at":"2015-02-05T01:57:41Z","updated_at":"2015-02-05T01:58:47Z","due_on":null,"closed_at":null},"comments":2,"created_at":"2015-02-05T00:48:24Z","updated_at":"2015-02-07T21:20:02Z","closed_at":null,"body":"During initial sync the process periodically terminates with:\r\n\r\n```\r\nSegmentation fault: 11\r\n```\r\n\r\nIt restarts and continues fine, eventually hitting it again.\r\n\r\nThis could be resulting from a memory allocation failure due to limited RAM on this older machine (with 4GB RAM)."},"comment":{"url":"https://api.github.com/repos/libbitcoin/libbitcoin-server/issues/comments/73383678","html_url":"https://github.com/libbitcoin/libbitcoin-server/issues/36#issuecomment-73383678","issue_url":"https://api.github.com/repos/libbitcoin/libbitcoin-server/issues/36","id":73383678,"user":{"login":"thecodefactory","id":5875399,"avatar_url":"https://avatars.githubusercontent.com/u/5875399?v=3","gravatar_id":"","url":"https://api.github.com/users/thecodefactory","html_url":"https://github.com/thecodefactory","followers_url":"https://api.github.com/users/thecodefactory/followers","following_url":"https://api.github.com/users/thecodefactory/following{/other_user}","gists_url":"https://api.github.com/users/thecodefactory/gists{/gist_id}","starred_url":"https://api.github.com/users/thecodefactory/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/thecodefactory/subscriptions","organizations_url":"https://api.github.com/users/thecodefactory/orgs","repos_url":"https://api.github.com/users/thecodefactory/repos","events_url":"https://api.github.com/users/thecodefactory/events{/privacy}","received_events_url":"https://api.github.com/users/thecodefactory/received_events","type":"User","site_admin":false},"created_at":"2015-02-07T21:20:02Z","updated_at":"2015-02-07T21:20:02Z","body":"I have been able to consistently reproduce a crash bug on initial sync using a 16GB Debian machine.  The compiled code uses gcc, and it happens with or without debugging enabled.\r\n\r\nI am pasting the gdb output:\r\n```\r\n#0  __memcmp_sse2 () at ../sysdeps/x86_64/multiarch/../memcmp.S:136\r\n#1  0x00007ffff701207d in equal<unsigned char> (__first2=0x14a9f61262119804 <error: Cannot access memory at address 0x14a9f61262119804>, \r\n    __last1=<optimized out>, \r\n    __first1=0x7ff4c401ac98 \"u\\260\\263\\306ܸ\\017\\252\\307\\341\\334\\314\\356\\325\\330N\\366\\262j\\006\\313z?\\221\\031\\224\\235\\315\\177\\357\\\"\\200\\020Q\")\r\n    at /usr/include/c++/4.9/bits/stl_algobase.h:822\r\n#2  __equal_aux<unsigned char const*, unsigned char const*> (__first2=0x14a9f61262119804 <error: Cannot access memory at address 0x14a9f61262119804>, \r\n    __last1=<optimized out>, \r\n    __first1=0x7ff4c401ac98 \"u\\260\\263\\306ܸ\\017\\252\\307\\341\\334\\314\\356\\325\\330N\\366\\262j\\006\\313z?\\221\\031\\224\\235\\315\\177\\357\\\"\\200\\020Q\")\r\n    at /usr/include/c++/4.9/bits/stl_algobase.h:838\r\n#3  equal<unsigned char const*, unsigned char const*> (__first2=0x14a9f61262119804 <error: Cannot access memory at address 0x14a9f61262119804>, \r\n    __last1=<optimized out>, \r\n    __first1=0x7ff4c401ac98 \"u\\260\\263\\306ܸ\\017\\252\\307\\341\\334\\314\\356\\325\\330N\\366\\262j\\006\\313z?\\221\\031\\224\\235\\315\\177\\357\\\"\\200\\020Q\")\r\n    at /usr/include/c++/4.9/bits/stl_algobase.h:1059\r\n#4  compare (this=<synthetic pointer>, key=...) at ./include/bitcoin/blockchain/impl/htdb_slab_list_item.ipp:96\r\n#5  get (key=..., this=<optimized out>) at ./include/bitcoin/blockchain/impl/htdb_slab.ipp:63\r\n#6  libbitcoin::chain::transaction_database::get (this=0x7fffffffdc48, hash=...) at src/database/transaction_database.cpp:92\r\n#7  0x00007ffff701f711 in operator() (slock=248, __closure=0x7ff4c401ac90) at src/impl/blockchain_impl.cpp:274\r\n#8  std::_Function_handler<bool(long unsigned int), libbitcoin::chain::blockchain_impl::fetch_transaction(const hash_digest&, libbitcoin::chain::blockchain::fetch_handler_transaction)::<lambda(size_t)> >::_M_invoke(const std::_Any_data &, unsigned long) (__functor=..., __args#0=248)\r\n    at /usr/include/c++/4.9/functional:2025\r\n#9  0x00007ffff701aba9 in operator() (__args#0=<optimized out>, this=0x7fffe9ffacc0) at /usr/include/c++/4.9/functional:2439\r\n#10 operator() (__closure=0x7fffe9ffacb8) at src/impl/blockchain_impl.cpp:166\r\n#11 operator() (__closure=<optimized out>) at src/impl/blockchain_impl.cpp:175\r\n#12 asio_handler_invoke<libbitcoin::chain::blockchain_impl::fetch(libbitcoin::chain::blockchain_impl::perform_read_functor)::<lambda()> > (function=...)\r\n    at /usr/include/boost/asio/handler_invoke_hook.hpp:69\r\n#13 invoke<libbitcoin::chain::blockchain_impl::fetch(libbitcoin::chain::blockchain_impl::perform_read_functor)::<lambda()>, libbitcoin::chain::blockchain_impl::fetch(libbitcoin::chain::blockchain_impl::perform_read_functor)::<lambda()> > (context=..., function=...)\r\n    at /usr/include/boost/asio/detail/handler_invoke_helpers.hpp:37\r\n#14 boost::asio::detail::completion_handler<libbitcoin::chain::blockchain_impl::fetch(libbitcoin::chain::blockchain_impl::perform_read_functor)::<lambda()> >::do_complete(boost::asio::detail::io_service_impl *, boost::asio::detail::operation *, const boost::system::error_code &, std::size_t) (\r\n    owner=<optimized out>, base=<optimized out>) at /usr/include/boost/asio/detail/completion_handler.hpp:68\r\n#15 0x00007ffff6d87648 in complete (bytes_transferred=0, ec=..., owner=..., this=<optimized out>)\r\n    at /usr/include/boost/asio/detail/task_io_service_operation.hpp:38\r\n#16 do_run_one (ec=..., this_thread=..., lock=..., this=0x6bae20) at /usr/include/boost/asio/detail/impl/task_io_service.ipp:384\r\n#17 run (ec=..., this=0x6bae20) at /usr/include/boost/asio/detail/impl/task_io_service.ipp:153\r\n#18 run (this=<optimized out>) at /usr/include/boost/asio/impl/io_service.ipp:59\r\n#19 operator() (__closure=<optimized out>) at src/utility/threadpool.cpp:51\r\n#20 _M_invoke<> (this=<optimized out>) at /usr/include/c++/4.9/functional:1700\r\n#21 operator() (this=<optimized out>) at /usr/include/c++/4.9/functional:1688\r\n#22 std::thread::_Impl<std::_Bind_simple<libbitcoin::threadpool::spawn_once()::<lambda()>()> >::_M_run(void) (this=<optimized out>)\r\n    at /usr/include/c++/4.9/thread:115\r\n#23 0x00007ffff5838970 in ?? () from /usr/lib/x86_64-linux-gnu/libstdc++.so.6\r\n#24 0x00007ffff6a690a4 in start_thread (arg=0x7fffe9ffb700) at pthread_create.c:309\r\n#25 0x00007ffff4fa7ccd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:111\r\n```\r\n\r\nHere is the valgrind output (on a different run, but clearly in the same piece of code, indicating memory corruption):\r\n\r\n```\r\n==2933== Thread 8:\r\n==2933== Invalid read of size 1\r\n==2933==    at 0x4C2ED2C: __memcmp_sse4_1 (vg_replace_strmem.c:972)\r\n==2933==    by 0x5A1F07C: equal<unsigned char> (stl_algobase.h:822)\r\n==2933==    by 0x5A1F07C: __equal_aux<unsigned char const*, unsigned char const*> (stl_algobase.h:838)\r\n==2933==    by 0x5A1F07C: equal<unsigned char const*, unsigned char const*> (stl_algobase.h:1059)\r\n==2933==    by 0x5A1F07C: compare (htdb_slab_list_item.ipp:96)\r\n==2933==    by 0x5A1F07C: get (htdb_slab.ipp:63)\r\n==2933==    by 0x5A1F07C: libbitcoin::chain::transaction_database::get(std::array<unsigned char, 32ul> const&) const (transaction_database.cpp:92)\r\n==2933==    by 0x5A29596: operator() (blockchain_impl.cpp:292)\r\n==2933==    by 0x5A29596: std::_Function_handler<bool (unsigned long), libbitcoin::chain::blockchain_impl::fetch_transaction_index(std::array<unsigned char, 32ul> const&, std::function<void (std::error_code const&, unsigned long, unsigned long)>)::{lambda(unsigned long)#1}>::_M_invoke(std::_Any_data const&, unsigned long) (functional:2025)\r\n==2933==    by 0x5A27BA8: operator() (functional:2439)\r\n==2933==    by 0x5A27BA8: operator() (blockchain_impl.cpp:166)\r\n==2933==    by 0x5A27BA8: operator() (blockchain_impl.cpp:175)\r\n==2933==    by 0x5A27BA8: asio_handler_invoke<libbitcoin::chain::blockchain_impl::fetch(libbitcoin::chain::blockchain_impl::perform_read_functor)::<lambda()> > (handler_invoke_hook.hpp:69)\r\n==2933==    by 0x5A27BA8: invoke<libbitcoin::chain::blockchain_impl::fetch(libbitcoin::chain::blockchain_impl::perform_read_functor)::<lambda()>, libbitcoin::chain::blockchain_impl::fetch(libbitcoin::chain::blockchain_impl::perform_read_functor)::<lambda()> > (handler_invoke_helpers.hpp:37)\r\n==2933==    by 0x5A27BA8: boost::asio::detail::completion_handler<libbitcoin::chain::blockchain_impl::fetch(std::function<bool (unsigned long)>)::{lambda()#2}>::do_complete(boost::asio::detail::task_io_service*, boost::asio::detail::task_io_service_operation*, boost::system::error_code const&, unsigned long) (completion_handler.hpp:68)\r\n==2933==    by 0x5D53647: complete (task_io_service_operation.hpp:38)\r\n==2933==    by 0x5D53647: do_run_one (task_io_service.ipp:384)\r\n==2933==    by 0x5D53647: run (task_io_service.ipp:153)\r\n==2933==    by 0x5D53647: run (io_service.ipp:59)\r\n==2933==    by 0x5D53647: operator() (threadpool.cpp:51)\r\n==2933==    by 0x5D53647: _M_invoke<> (functional:1700)\r\n==2933==    by 0x5D53647: operator() (functional:1688)\r\n==2933==    by 0x5D53647: std::thread::_Impl<std::_Bind_simple<libbitcoin::threadpool::spawn_once()::{lambda()#1} ()> >::_M_run() (thread:115)\r\n==2933==    by 0x723A96F: ??? (in /usr/lib/x86_64-linux-gnu/libstdc++.so.6.0.20)\r\n==2933==    by 0x5F9B0A3: start_thread (pthread_create.c:309)\r\n==2933==    by 0x7A8BCCC: clone (clone.S:111)\r\n==2933==  Address 0x217caf5e2a72b070 is not stack'd, malloc'd or (recently) free'd\r\n```\r\n"}}