nghttpx: Reset both timeouts when either read or write succeeds
Previously read and write timeouts work independently. When we are writing response to the client, read timeout still ticks (e.g., HTTP/2 or tunneled HTTPS connection). So read timeout may occur during long download. This commit fixes this issue. This commit only fixes the upstream part. We need similar fix for the downstream.
This commit is contained in:
parent
727662257c
commit
b305495a75
|
@ -49,6 +49,10 @@ namespace {
|
|||
void upstream_readcb(bufferevent *bev, void *arg)
|
||||
{
|
||||
auto handler = static_cast<ClientHandler*>(arg);
|
||||
auto upstream = handler->get_upstream();
|
||||
if(upstream) {
|
||||
upstream->reset_timeouts();
|
||||
}
|
||||
int rv = handler->on_read();
|
||||
if(rv != 0) {
|
||||
delete handler;
|
||||
|
@ -60,6 +64,10 @@ namespace {
|
|||
void upstream_writecb(bufferevent *bev, void *arg)
|
||||
{
|
||||
auto handler = static_cast<ClientHandler*>(arg);
|
||||
auto upstream = handler->get_upstream();
|
||||
if(upstream) {
|
||||
upstream->reset_timeouts();
|
||||
}
|
||||
|
||||
// We actually depend on write low-water mark == 0.
|
||||
if(handler->get_outbuf_length() > 0) {
|
||||
|
@ -71,7 +79,7 @@ void upstream_writecb(bufferevent *bev, void *arg)
|
|||
delete handler;
|
||||
return;
|
||||
}
|
||||
auto upstream = handler->get_upstream();
|
||||
|
||||
if(!upstream) {
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -627,8 +627,7 @@ Http2Upstream::Http2Upstream(ClientHandler *handler)
|
|||
session_(nullptr),
|
||||
settings_timerev_(nullptr)
|
||||
{
|
||||
handler->set_upstream_timeouts(&get_config()->http2_upstream_read_timeout,
|
||||
&get_config()->upstream_write_timeout);
|
||||
reset_timeouts();
|
||||
|
||||
int rv;
|
||||
|
||||
|
@ -1436,4 +1435,10 @@ int Http2Upstream::on_timeout(Downstream *downstream)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void Http2Upstream::reset_timeouts()
|
||||
{
|
||||
handler_->set_upstream_timeouts(&get_config()->http2_upstream_read_timeout,
|
||||
&get_config()->upstream_write_timeout);
|
||||
}
|
||||
|
||||
} // namespace shrpx
|
||||
|
|
|
@ -73,6 +73,8 @@ public:
|
|||
const uint8_t *data, size_t len, bool flush);
|
||||
virtual int on_downstream_body_complete(Downstream *downstream);
|
||||
|
||||
virtual void reset_timeouts();
|
||||
|
||||
bool get_flow_control() const;
|
||||
// Perform HTTP/2 upgrade from |upstream|. On success, this object
|
||||
// takes ownership of the |upstream|. This function returns 0 if it
|
||||
|
|
|
@ -973,4 +973,10 @@ void HttpsUpstream::log_response_headers(const std::string& hdrs) const
|
|||
ULOG(INFO, this) << "HTTP response headers\n" << hdrp;
|
||||
}
|
||||
|
||||
void HttpsUpstream::reset_timeouts()
|
||||
{
|
||||
handler_->set_upstream_timeouts(&get_config()->upstream_read_timeout,
|
||||
&get_config()->upstream_write_timeout);
|
||||
}
|
||||
|
||||
} // namespace shrpx
|
||||
|
|
|
@ -67,6 +67,8 @@ public:
|
|||
const uint8_t *data, size_t len, bool flush);
|
||||
virtual int on_downstream_body_complete(Downstream *downstream);
|
||||
|
||||
virtual void reset_timeouts();
|
||||
|
||||
void reset_current_header_length();
|
||||
void log_response_headers(const std::string& hdrs) const;
|
||||
private:
|
||||
|
|
|
@ -437,8 +437,7 @@ SpdyUpstream::SpdyUpstream(uint16_t version, ClientHandler *handler)
|
|||
session_(nullptr)
|
||||
{
|
||||
//handler->set_bev_cb(spdy_readcb, 0, spdy_eventcb);
|
||||
handler->set_upstream_timeouts(&get_config()->http2_upstream_read_timeout,
|
||||
&get_config()->upstream_write_timeout);
|
||||
reset_timeouts();
|
||||
|
||||
spdylay_session_callbacks callbacks;
|
||||
memset(&callbacks, 0, sizeof(callbacks));
|
||||
|
@ -1129,4 +1128,10 @@ int SpdyUpstream::on_timeout(Downstream *downstream)
|
|||
return 0;
|
||||
}
|
||||
|
||||
void SpdyUpstream::reset_timeouts()
|
||||
{
|
||||
handler_->set_upstream_timeouts(&get_config()->http2_upstream_read_timeout,
|
||||
&get_config()->upstream_write_timeout);
|
||||
}
|
||||
|
||||
} // namespace shrpx
|
||||
|
|
|
@ -72,6 +72,8 @@ public:
|
|||
const uint8_t *data, size_t len, bool flush);
|
||||
virtual int on_downstream_body_complete(Downstream *downstream);
|
||||
|
||||
virtual void reset_timeouts();
|
||||
|
||||
bool get_flow_control() const;
|
||||
|
||||
int consume(int32_t stream_id, size_t len);
|
||||
|
|
|
@ -59,6 +59,8 @@ public:
|
|||
virtual void pause_read(IOCtrlReason reason) = 0;
|
||||
virtual int resume_read(IOCtrlReason reason, Downstream *downstream,
|
||||
size_t consumed) = 0;
|
||||
|
||||
virtual void reset_timeouts() = 0;
|
||||
};
|
||||
|
||||
} // namespace shrpx
|
||||
|
|
Loading…
Reference in New Issue