nghttpx: Close and disallow h1 backend connection on backend replacement

This commit is contained in:
Tatsuhiro Tsujikawa 2016-06-04 12:16:31 +09:00
parent 0ca7c4cb38
commit cb7269f334
6 changed files with 25 additions and 8 deletions

View File

@ -29,10 +29,14 @@ namespace shrpx {
DownstreamConnectionPool::DownstreamConnectionPool() {}
DownstreamConnectionPool::~DownstreamConnectionPool() {
DownstreamConnectionPool::~DownstreamConnectionPool() { remove_all(); }
void DownstreamConnectionPool::remove_all() {
for (auto dconn : pool_) {
delete dconn;
}
pool_.clear();
}
void DownstreamConnectionPool::add_downstream_connection(

View File

@ -42,6 +42,7 @@ public:
void add_downstream_connection(std::unique_ptr<DownstreamConnection> dconn);
std::unique_ptr<DownstreamConnection> pop_downstream_connection();
void remove_downstream_connection(DownstreamConnection *dconn);
void remove_all();
private:
std::set<DownstreamConnection *> pool_;

View File

@ -166,7 +166,11 @@ HttpDownstreamConnection::HttpDownstreamConnection(
ioctrl_(&conn_.rlimit),
response_htp_{0} {}
HttpDownstreamConnection::~HttpDownstreamConnection() {}
HttpDownstreamConnection::~HttpDownstreamConnection() {
if (LOG_ENABLED(INFO)) {
DCLOG(INFO, this) << "Deleted";
}
}
int HttpDownstreamConnection::attach_downstream(Downstream *downstream) {
if (LOG_ENABLED(INFO)) {
@ -1173,4 +1177,6 @@ HttpDownstreamConnection::get_downstream_addr_group() const {
DownstreamAddr *HttpDownstreamConnection::get_addr() const { return addr_; }
bool HttpDownstreamConnection::poolable() const { return !group_->retired; }
} // namespace shrpx

View File

@ -61,7 +61,7 @@ public:
virtual void on_upstream_change(Upstream *upstream);
virtual bool poolable() const { return true; }
virtual bool poolable() const;
virtual DownstreamAddrGroup *get_downstream_addr_group() const;

View File

@ -141,6 +141,11 @@ Worker::Worker(struct ev_loop *loop, SSL_CTX *sv_ssl_ctx, SSL_CTX *cl_ssl_ctx,
void Worker::replace_downstream_config(
std::shared_ptr<DownstreamConfig> downstreamconf) {
for (auto &g : downstream_addr_groups_) {
g->retired = true;
g->shared_addr->dconn_pool.remove_all();
}
downstreamconf_ = downstreamconf;
downstream_addr_groups_ = std::vector<std::shared_ptr<DownstreamAddrGroup>>(
@ -153,14 +158,11 @@ void Worker::replace_downstream_config(
dst = std::make_shared<DownstreamAddrGroup>();
dst->pattern = src.pattern;
// TODO for some reason, clang-3.6 which comes with Ubuntu 15.10
// does not value initialize with std::make_shared.
auto shared_addr = std::make_shared<SharedDownstreamAddr>();
// TODO for some reason, clang-3.6 which comes with Ubuntu 15.10
// does not value initialize SharedDownstreamAddr above.
shared_addr->next = 0;
shared_addr->addrs.resize(src.addrs.size());
shared_addr->http1_pri = {};
shared_addr->http2_pri = {};
size_t num_http1 = 0;
size_t num_http2 = 0;

View File

@ -144,6 +144,10 @@ struct SharedDownstreamAddr {
struct DownstreamAddrGroup {
ImmutableString pattern;
std::shared_ptr<SharedDownstreamAddr> shared_addr;
// true if this group is no longer used for new request. If this is
// true, the connection made using one of address in shared_addr
// must not be pooled.
bool retired;
};
struct WorkerStat {