Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed a minor bug in the connection pool: we should resume the "name"…

…, "sockaddr", and "socklen" fields for the connection from the pool such that we can get more detailed error log messages with the "upstream: postgres://ip.add.re.ss:port" bit.
  • Loading branch information...
commit 5dd0c57f410705307d40cc1d93e3a2f9eab24572 1 parent c605b58
@agentzh agentzh authored
Showing with 14 additions and 6 deletions.
  1. +13 −5 src/ngx_postgres_keepalive.c
  2. +1 −1  src/ngx_postgres_keepalive.h
View
18 src/ngx_postgres_keepalive.c
@@ -85,13 +85,17 @@ ngx_postgres_keepalive_get_peer_single(ngx_peer_connection_t *pc,
c->read->log = pc->log;
c->write->log = pc->log;
- pc->connection = c;
- pc->cached = 1;
-
pgp->name = &item->name;
pgp->pgconn = item->pgconn;
+ pc->connection = c;
+ pc->cached = 1;
+ pc->name = pgp->name;
+ pc->sockaddr = &item->sockaddr;
+ pc->socklen = item->socklen;
+
dd("returning NGX_DONE");
+
return NGX_DONE;
}
@@ -186,6 +190,7 @@ ngx_postgres_keepalive_free_peer(ngx_peer_connection_t *pc,
ngx_postgres_upstream_free_connection(pc->log, item->connection,
item->pgconn, pgscf);
+
} else {
q = ngx_queue_head(&pgscf->free);
ngx_queue_remove(q);
@@ -216,10 +221,13 @@ ngx_postgres_keepalive_free_peer(ngx_peer_connection_t *pc,
c->read->log = ngx_cycle->log;
c->write->log = ngx_cycle->log;
- item->socklen = pc->socklen;
- ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen);
+ if (pc->sockaddr != &item->sockaddr) {
+ item->socklen = pc->socklen;
+ ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen);
+ }
item->pgconn = pgp->pgconn;
+ item->name = *pgp->name;
}
dd("returning");
View
2  src/ngx_postgres_keepalive.h
@@ -41,7 +41,7 @@ typedef struct {
ngx_postgres_upstream_srv_conf_t *srv_conf;
ngx_connection_t *connection;
PGconn *pgconn;
- struct sockaddr_storage sockaddr;
+ struct sockaddr sockaddr;
socklen_t socklen;
ngx_str_t name;
} ngx_postgres_keepalive_cache_t;
Please sign in to comment.
Something went wrong with that request. Please try again.