Fixed assertion failure. Resume downstream read on SPDY stream close.

This commit is contained in:
Tatsuhiro Tsujikawa 2012-06-06 21:39:55 +09:00
parent 4ac689526b
commit faee23a925
5 changed files with 25 additions and 5 deletions

View File

@ -87,6 +87,11 @@ bool Downstream::resume_read(IOCtrlReason reason)
return ioctrl_.resume_read(reason);
}
void Downstream::force_resume_read()
{
ioctrl_.force_resume_read();
}
namespace {
void check_transfer_encoding_chunked(bool *chunked,
const Headers::value_type &item)
@ -416,12 +421,13 @@ void body_buf_cb(evbuffer *body, size_t oldlen, size_t newlen, void *arg)
int Downstream::init_response_body_buf()
{
assert(response_body_buf_ == 0);
response_body_buf_ = evbuffer_new();
if(response_body_buf_ == 0) {
DIE();
if(!response_body_buf_) {
response_body_buf_ = evbuffer_new();
if(response_body_buf_ == 0) {
DIE();
}
evbuffer_setcb(response_body_buf_, body_buf_cb, this);
}
evbuffer_setcb(response_body_buf_, body_buf_cb, this);
return 0;
}

View File

@ -56,6 +56,7 @@ public:
int32_t get_stream_id() const;
void pause_read(IOCtrlReason reason);
bool resume_read(IOCtrlReason reason);
void force_resume_read();
// downstream request API
const Headers& get_request_headers() const;
void add_request_header(const std::string& name, const std::string& value);

View File

@ -58,4 +58,10 @@ bool IOControl::resume_read(IOCtrlReason reason)
}
}
void IOControl::force_resume_read()
{
std::fill(ctrlv_.begin(), ctrlv_.end(), 0);
bufferevent_enable(bev_, EV_READ);
}
} // namespace shrpx

View File

@ -48,6 +48,8 @@ public:
void pause_read(IOCtrlReason reason);
// Returns true if read operation is enabled after this call
bool resume_read(IOCtrlReason reason);
// Clear all pause flags and enable read
void force_resume_read();
private:
bufferevent *bev_;
std::vector<int> ctrlv_;

View File

@ -103,6 +103,11 @@ void on_stream_close_callback
if(downstream->get_response_state() == Downstream::MSG_COMPLETE) {
upstream->get_downstream_queue()->remove(downstream);
delete downstream;
} else {
// At this point, downstream read may be paused. To reclaim
// file descriptor, enable read here and catch read
// notification. And delete downstream there.
downstream->force_resume_read();
}
}
}