
river at svn
Jul 23, 2008, 2:31 AM
Post #1 of 1
(44 views)
Permalink
|
|
SVN: [37944] trunk/switchboard
|
|
Revision: 37944 Author: river Date: 2008-07-23 09:31:42 +0000 (Wed, 23 Jul 2008) Log Message: ----------- fcgi_record_writer needs to track alive_ to avoid race between socket close/cancel and async function call causing assert failure switchboard: fcgi_record_writer.h:167: void fcgi_record_writer<Socket>::write_done(asio::error_code, size_t, boost::function<void ()(asio::error_code), std::allocator<void> >) [with Socket = asio::basic_stream_socket<asio::ip::tcp, asio::stream_socket_service<asio::ip::tcp> >]: Assertion `socket_.native() != -1' failed. Modified Paths: -------------- trunk/switchboard/fcgi_record_writer.h trunk/switchboard/fcgi_server_connection.h trunk/switchboard/fcgi_socket.h Modified: trunk/switchboard/fcgi_record_writer.h =================================================================== --- trunk/switchboard/fcgi_record_writer.h 2008-07-23 08:51:31 UTC (rev 37943) +++ trunk/switchboard/fcgi_record_writer.h 2008-07-23 09:31:42 UTC (rev 37944) @@ -49,6 +49,7 @@ boost::function <void(asio::error_code)>); void write_noflush(fcgi::recordp record); void flush(boost::function<void (asio::error_code)>); + void close(); private: sbcontext &context_; @@ -56,6 +57,7 @@ std::vector<record_writer_detail::pending_record> inflight_; std::vector<record_writer_detail::pending_record> waiting_; std::vector<asio::mutable_buffer> buffers_; + bool alive_; void write_done( asio::error_code error, @@ -76,13 +78,13 @@ typedef boost::shared_ptr<fcgi_record_writer<asio::ip::tcp::socket> > fcgi_record_writer_tcpp; typedef boost::shared_ptr<fcgi_record_writer<asio::local::stream_protocol::socket> > fcgi_record_writer_unixp; - template<typename Socket> fcgi_record_writer<Socket>::fcgi_record_writer( sbcontext &context, Socket &socket) : context_(context) , socket_(socket) + , alive_(true) , logger(log4cxx::Logger::getLogger("switchboard.fcgi_record_writer")) { LOG4CXX_DEBUG(logger, boost::format("record_writer@%p: created") % this); @@ -90,10 +92,20 @@ template<typename Socket> void +fcgi_record_writer<Socket>::close() +{ + alive_ = false; +} + +template<typename Socket> +void fcgi_record_writer<Socket>::write_noflush(fcgi::recordp record) { LOG4CXX_DEBUG(logger, boost::format("record_writer@%p: write_noflush()") % this); + if (!alive_) + return; + record_writer_detail::pending_record pend = { record, { @@ -112,6 +124,9 @@ fcgi::recordp record, boost::function<void (asio::error_code)> func) { + if (!alive_) + return; + assert(socket_.native() != -1); LOG4CXX_DEBUG(logger, boost::format("record_writer@%p: write()") % this); @@ -124,6 +139,9 @@ void fcgi_record_writer<Socket>::flush(boost::function<void (asio::error_code)> func) { + if (!alive_) + return; + assert(socket_.native() != -1); if (!inflight_.empty() || waiting_.empty()) { func(asio::error_code()); @@ -159,6 +177,9 @@ std::size_t bytes, boost::function<void (asio::error_code)> func) { + if (!alive_) + return; + if (error) { func(error); return; Modified: trunk/switchboard/fcgi_server_connection.h =================================================================== --- trunk/switchboard/fcgi_server_connection.h 2008-07-23 08:51:31 UTC (rev 37943) +++ trunk/switchboard/fcgi_server_connection.h 2008-07-23 09:31:42 UTC (rev 37944) @@ -67,7 +67,6 @@ { } - //boost::shared_ptr<fcgi_socket<typename Protocol::socket> > &socket(); fcgi_socket_basep socket() { return boost::static_pointer_cast<fcgi_socket<typename Protocol::socket> >(socket_); } Modified: trunk/switchboard/fcgi_socket.h =================================================================== --- trunk/switchboard/fcgi_socket.h 2008-07-23 08:51:31 UTC (rev 37943) +++ trunk/switchboard/fcgi_socket.h 2008-07-23 09:31:42 UTC (rev 37944) @@ -118,6 +118,7 @@ alive_ = false; close_sig_(); + writer_->close(); writer_.reset(); socket_.close(); } _______________________________________________ MediaWiki-CVS mailing list MediaWiki-CVS[at]lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-cvs
|