On Thu, May 13, 2010 at 5:51 AM, Jorge Moraleda <jorge.moral...@gmail.com>wrote:

> I still have not been able to write a small test case that will
> reproduce my race conditions. For what is worth, these are the
> relevant parts of the drd log for one of the race conditions.
> Everything that is not in namespaces std or boost is mine. I am using
> boost 1.42 and gcc 4.4.4 on debian.
>
> ==28087== Thread 9:
> ==28087== Conflicting store by thread 9 at 0x10cf9e8d size 1
> ==28087==    at 0x6E587AA: std::string::operator+=(char) (in
> /usr/lib/libstdc++.so.6.0.13)
> ==28087==    by 0x9E3016: boost::filesystem::basic_path<std::string,
> boost::filesystem::path_traits>::m_append(char) (path.hpp:1108)
> ==28087==    by 0x9E0BB5: boost::filesystem::basic_path<std::string,
> boost::filesystem::path_traits>::operator/=(char const*)
> (path.hpp:1128)
> ==28087==    by 0x9DDAE1: boost::filesystem::basic_path<std::string,
> boost::filesystem::path_traits>::basic_path(char const*)
> (path.hpp:167)
> ==28087==    by 0xA562ED:
> ripe_server::request_parser::consume(ripe_server::request&, char)
> (request_parser.cpp:29)
> ==28087==    by 0x9F266F: boost::tuples::tuple<boost::logic::tribool,
> char*, boost::tuples::null_type, boost::tuples::null_type,
> boost::tuples::null_type, boost::tuples::null_type,
> boost::tuples::null_type, boost::tuples::null_type,
> boost::tuples::null_type, boost::tuples::null_type>
> ripe_server::request_parser::parse<char*>(ripe_server::request&,
> char*, char*) (request_parser.hpp:45)
> ==28087==    by 0x9EF523:
> ripe_server::connection::handle_read(boost::system::error_code const&,
> unsigned long) (connection.cpp:50)
> ==28087==    by 0xA04532: void boost::_mfi::mf2<void,
> ripe_server::connection, boost::system::error_code const&, unsigned
> long>::call<boost::shared_ptr<ripe_server::connection>,
> boost::system::error_code const, unsigned
> long>(boost::shared_ptr<ripe_server::connection>&, void const*,
> boost::system::error_code const&, unsigned long&) const
> (mem_fn_template.hpp:271)
> ==28087==    by 0xA041EA: void boost::_mfi::mf2<void,
> ripe_server::connection, boost::system::error_code const&, unsigned
> long>::operator()<boost::shared_ptr<ripe_server::connection>
> >(boost::shared_ptr<ripe_server::connection>&,
> boost::system::error_code const&, unsigned long) const
> (mem_fn_template.hpp:286)
> ==28087==    by 0xA045B5: void
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2>
> (*)()>::operator()<boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
> boost::_bi::list2<boost::system::error_code&, unsigned long&>
> >(boost::_bi::type<void>, boost::_mfi::mf2<void,
> ripe_server::connection, boost::system::error_code const&, unsigned
> long>&, boost::_bi::list2<boost::system::error_code&, unsigned
> long&>&, int) (bind.hpp:392)
> ==28087==    by 0xA042C3: void boost::_bi::bind_t<void,
> boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2> (*)()>
> >::operator()<boost::system::error_code, unsigned
> long>(boost::system::error_code&, unsigned long&)
> (bind_template.hpp:61)
> ==28087==    by 0xA03EB4:
> boost::asio::detail::binder2<boost::_bi::bind_t<void,
> boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2> (*)()> >,
> boost::system::error_code, unsigned long>::operator()()
> (bind_handler.hpp:96)
> ==28087== Address 0x10cf9e8d is at offset 61 from 0x10cf9e50.
> Allocation context:
> ==28087==    at 0x4C24FD1: operator new(unsigned long)
> (vg_replace_malloc.c:261)
> ==28087==    by 0x6E56B38: std::string::_Rep::_S_create(unsigned long,
> unsigned long, std::allocator<char> const&) (in
> /usr/lib/libstdc++.so.6.0.13)
> ==28087==    by 0x6E57AFA:
> std::string::_Rep::_M_clone(std::allocator<char> const&, unsigned
> long) (in /usr/lib/libstdc++.so.6.0.13)
> ==28087==    by 0x6E5806B: std::string::reserve(unsigned long) (in
> /usr/lib/libstdc++.so.6.0.13)
> ==28087==    by 0x6E5876D: std::string::operator+=(char) (in
> /usr/lib/libstdc++.so.6.0.13)
> ==28087==    by 0x9E3016: boost::filesystem::basic_path<std::string,
> boost::filesystem::path_traits>::m_append(char) (path.hpp:1108)
> ==28087==    by 0x9E0BB5: boost::filesystem::basic_path<std::string,
> boost::filesystem::path_traits>::operator/=(char const*)
> (path.hpp:1128)
> ==28087==    by 0x9DDAE1: boost::filesystem::basic_path<std::string,
> boost::filesystem::path_traits>::basic_path(char const*)
> (path.hpp:167)
> ==28087==    by 0xA562ED:
> ripe_server::request_parser::consume(ripe_server::request&, char)
> (request_parser.cpp:29)
> ==28087==    by 0x9F266F: boost::tuples::tuple<boost::logic::tribool,
> char*, boost::tuples::null_type, boost::tuples::null_type,
> boost::tuples::null_type, boost::tuples::null_type,
> boost::tuples::null_type, boost::tuples::null_type,
> boost::tuples::null_type, boost::tuples::null_type>
> ripe_server::request_parser::parse<char*>(ripe_server::request&,
> char*, char*) (request_parser.hpp:45)
> ==28087==    by 0x9EF523:
> ripe_server::connection::handle_read(boost::system::error_code const&,
> unsigned long) (connection.cpp:50)
> ==28087==    by 0xA04532: void boost::_mfi::mf2<void,
> ripe_server::connection, boost::system::error_code const&, unsigned
> long>::call<boost::shared_ptr<ripe_server::connection>,
> boost::system::error_code const, unsigned
> long>(boost::shared_ptr<ripe_server::connection>&, void const*,
> boost::system::error_code const&, unsigned long&) const
> (mem_fn_template.hpp:271)
> ==28087== Other segment start (thread 10)
> ==28087==    at 0x4C2D283: pthread_mutex_lock
> (drd_pthread_intercepts.c:580)
> ==28087==    by 0x6E1B21E: std::locale::locale() (in
> /usr/lib/libstdc++.so.6.0.13)
> ==28087==    by 0x6E52B58: std::basic_istringstream<char,
> std::char_traits<char>, std::allocator<char>
> >::basic_istringstream(std::string const&, std::_Ios_Openmode) (in
> /usr/lib/libstdc++.so.6.0.13)
> ==28087==    by 0xA502EF:
> ripe_server::request_handler::handle_request(ripe_server::request&,
> ripe_server::reply&) (request_handler.cpp:221)
> ==28087==    by 0x9EF634:
> ripe_server::connection::handle_read(boost::system::error_code const&,
> unsigned long) (connection.cpp:54)
> ==28087==    by 0xA04532: void boost::_mfi::mf2<void,
> ripe_server::connection, boost::system::error_code const&, unsigned
> long>::call<boost::shared_ptr<ripe_server::connection>,
> boost::system::error_code const, unsigned
> long>(boost::shared_ptr<ripe_server::connection>&, void const*,
> boost::system::error_code const&, unsigned long&) const
> (mem_fn_template.hpp:271)
> ==28087==    by 0xA041EA: void boost::_mfi::mf2<void,
> ripe_server::connection, boost::system::error_code const&, unsigned
> long>::operator()<boost::shared_ptr<ripe_server::connection>
> >(boost::shared_ptr<ripe_server::connection>&,
> boost::system::error_code const&, unsigned long) const
> (mem_fn_template.hpp:286)
> ==28087==    by 0xA045B5: void
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2>
> (*)()>::operator()<boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
> boost::_bi::list2<boost::system::error_code&, unsigned long&>
> >(boost::_bi::type<void>, boost::_mfi::mf2<void,
> ripe_server::connection, boost::system::error_code const&, unsigned
> long>&, boost::_bi::list2<boost::system::error_code&, unsigned
> long&>&, int) (bind.hpp:392)
> ==28087==    by 0xA042C3: void boost::_bi::bind_t<void,
> boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2> (*)()>
> >::operator()<boost::system::error_code, unsigned
> long>(boost::system::error_code&, unsigned long&)
> (bind_template.hpp:61)
> ==28087==    by 0xA03EB4:
> boost::asio::detail::binder2<boost::_bi::bind_t<void,
> boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2> (*)()> >,
> boost::system::error_code, unsigned long>::operator()()
> (bind_handler.hpp:96)
> ==28087==    by 0xA03BF7: void
>
> boost::asio::asio_handler_invoke<boost::asio::detail::binder2<boost::_bi::bind_t<void,
> boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2> (*)()> >,
> boost::system::error_code, unsigned long>
> >(boost::asio::detail::binder2<boost::_bi::bind_t<void,
> boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2> (*)()> >,
> boost::system::error_code, unsigned long>, ...)
> (handler_invoke_hook.hpp:62)
> ==28087==    by 0xA0392A: void
>
> boost_asio_handler_invoke_helpers::invoke<boost::asio::detail::binder2<boost::_bi::bind_t<void,
> boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2> (*)()> >,
> boost::system::error_code, unsigned long>, boost::_bi::bind_t<void,
> boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2> (*)()> >
> >(boost::asio::detail::binder2<boost::_bi::bind_t<void,
> boost::_mfi::mf2<void, ripe_server::connection,
> boost::system::error_code const&, unsigned long>,
>
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2> (*)()> >,
> boost::system::error_code, unsigned long> const&,
> boost::_bi::bind_t<void, boost::_mfi::mf2<void,
> ripe_server::connection, boost::system::error_code const&, unsigned
> long>,
> boost::_bi::list3<boost::_bi::value<boost::shared_ptr<ripe_server::connection>
> >, boost::arg<1> (*)(), boost::arg<2> (*)()> >&)
> (handler_invoke_helpers.hpp:41)
> [ ... ]
>

Unfortunately analyzing this output completely without access to all
involved source code is not possible.

Comparing the call stacks of the conflicting memory access and the memory
allocation site is interesting however. The topmost stack frames show
manipulation of a std::string object from inside a
boost::filesystem::basic_path object. Instances of those classes can be
manipulated safely inside a thread but must be protected against concurrent
accesses. How does the function ripe_server::request_parser::consume()
access basic_path objects ? Maybe this function is manipulating the same
boost::filesystem::basic_path object from two different threads without
proper locking ? Other stack frames show that the
ripe_server::request_parser::consume() member function is invoked via a
shared pointer to a ripe_server::connection object
(boost::shared_ptr<ripe_server::connection>). Does this mean that methods of
the same ripe_server::connection object can be invoked from more than one
thread ? If so, are all methods of class ripe_server::connection thread-safe
?

Note: Valgrinds command-line option --num-callers might be helpful in order
to show more stack frames in race reports (see also
http://www.valgrind.org/docs/manual/manual-core.html#manual-core.erropts).

Bart.
------------------------------------------------------------------------------

_______________________________________________
Valgrind-users mailing list
Valgrind-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/valgrind-users

Reply via email to