r37944 MediaWiki - Code Review archive

Repository:MediaWiki
Revision:r37943‎ | r37944 | r37945 >
Date:09:31, 23 July 2008
Author:river
Status:old
Tags:
Comment:
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 (modified) (history)
  • /trunk/switchboard/fcgi_server_connection.h (modified) (history)
  • /trunk/switchboard/fcgi_socket.h (modified) (history)

Diff [purge]

Index: trunk/switchboard/fcgi_record_writer.h
@@ -49,6 +49,7 @@
5050 boost::function <void(asio::error_code)>);
5151 void write_noflush(fcgi::recordp record);
5252 void flush(boost::function<void (asio::error_code)>);
 53+ void close();
5354
5455 private:
5556 sbcontext &context_;
@@ -56,6 +57,7 @@
5758 std::vector<record_writer_detail::pending_record> inflight_;
5859 std::vector<record_writer_detail::pending_record> waiting_;
5960 std::vector<asio::mutable_buffer> buffers_;
 61+ bool alive_;
6062
6163 void write_done(
6264 asio::error_code error,
@@ -76,13 +78,13 @@
7779 typedef boost::shared_ptr<fcgi_record_writer<asio::ip::tcp::socket> > fcgi_record_writer_tcpp;
7880 typedef boost::shared_ptr<fcgi_record_writer<asio::local::stream_protocol::socket> > fcgi_record_writer_unixp;
7981
80 -
8182 template<typename Socket>
8283 fcgi_record_writer<Socket>::fcgi_record_writer(
8384 sbcontext &context,
8485 Socket &socket)
8586 : context_(context)
8687 , socket_(socket)
 88+ , alive_(true)
8789 , logger(log4cxx::Logger::getLogger("switchboard.fcgi_record_writer"))
8890 {
8991 LOG4CXX_DEBUG(logger, boost::format("record_writer@%p: created") % this);
@@ -90,10 +92,20 @@
9193
9294 template<typename Socket>
9395 void
 96+fcgi_record_writer<Socket>::close()
 97+{
 98+ alive_ = false;
 99+}
 100+
 101+template<typename Socket>
 102+void
94103 fcgi_record_writer<Socket>::write_noflush(fcgi::recordp record)
95104 {
96105 LOG4CXX_DEBUG(logger, boost::format("record_writer@%p: write_noflush()") % this);
97106
 107+ if (!alive_)
 108+ return;
 109+
98110 record_writer_detail::pending_record pend = {
99111 record,
100112 {
@@ -112,6 +124,9 @@
113125 fcgi::recordp record,
114126 boost::function<void (asio::error_code)> func)
115127 {
 128+ if (!alive_)
 129+ return;
 130+
116131 assert(socket_.native() != -1);
117132 LOG4CXX_DEBUG(logger, boost::format("record_writer@%p: write()") % this);
118133
@@ -124,6 +139,9 @@
125140 void
126141 fcgi_record_writer<Socket>::flush(boost::function<void (asio::error_code)> func)
127142 {
 143+ if (!alive_)
 144+ return;
 145+
128146 assert(socket_.native() != -1);
129147 if (!inflight_.empty() || waiting_.empty()) {
130148 func(asio::error_code());
@@ -159,6 +177,9 @@
160178 std::size_t bytes,
161179 boost::function<void (asio::error_code)> func)
162180 {
 181+ if (!alive_)
 182+ return;
 183+
163184 if (error) {
164185 func(error);
165186 return;
Index: trunk/switchboard/fcgi_server_connection.h
@@ -67,7 +67,6 @@
6868 {
6969 }
7070
71 - //boost::shared_ptr<fcgi_socket<typename Protocol::socket> > &socket();
7271 fcgi_socket_basep socket() {
7372 return boost::static_pointer_cast<fcgi_socket<typename Protocol::socket> >(socket_);
7473 }
Index: trunk/switchboard/fcgi_socket.h
@@ -118,6 +118,7 @@
119119
120120 alive_ = false;
121121 close_sig_();
 122+ writer_->close();
122123 writer_.reset();
123124 socket_.close();
124125 }

Status & tagging log