Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

fixed a bug in the connection pool: we should copy over the "name" an…

…d "sockaddr" fields instead of passing pointers around.
  • Loading branch information...
commit c62c673936772117c8e4141cbaf8b250c9bf77d0 1 parent 5dd0c57
@agentzh agentzh authored
View
26 src/ngx_postgres_keepalive.c
@@ -85,13 +85,19 @@ ngx_postgres_keepalive_get_peer_single(ngx_peer_connection_t *pc,
c->read->log = pc->log;
c->write->log = pc->log;
- pgp->name = &item->name;
+ pgp->name.data = item->name.data;
+ pgp->name.len = item->name.len;
+
+ pgp->sockaddr = item->sockaddr;
+
pgp->pgconn = item->pgconn;
pc->connection = c;
pc->cached = 1;
- pc->name = pgp->name;
- pc->sockaddr = &item->sockaddr;
+
+ pc->name = &pgp->name;
+
+ pc->sockaddr = &pgp->sockaddr;
pc->socklen = item->socklen;
dd("returning NGX_DONE");
@@ -137,7 +143,9 @@ ngx_postgres_keepalive_get_peer_multi(ngx_peer_connection_t *pc,
pc->connection = c;
pc->cached = 1;
- pgp->name = &item->name;
+ /* we do not need to resume the peer name
+ * because we already take the right value outside */
+
pgp->pgconn = item->pgconn;
dd("returning NGX_DONE");
@@ -221,13 +229,13 @@ ngx_postgres_keepalive_free_peer(ngx_peer_connection_t *pc,
c->read->log = ngx_cycle->log;
c->write->log = ngx_cycle->log;
- if (pc->sockaddr != &item->sockaddr) {
- item->socklen = pc->socklen;
- ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen);
- }
+ item->socklen = pc->socklen;
+ ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen);
item->pgconn = pgp->pgconn;
- item->name = *pgp->name;
+
+ item->name.data = pgp->name.data;
+ item->name.len = pgp->name.len;
}
dd("returning");
View
10 src/ngx_postgres_processor.c
@@ -185,7 +185,7 @@ ngx_postgres_upstream_connect(ngx_http_request_t *r, ngx_connection_t *pgxc,
dd("connection failed");
ngx_log_error(NGX_LOG_ERR, pgxc->log, 0,
"postgres: connection failed: %s in upstream \"%V\"",
- PQerrorMessage(pgdt->pgconn), pgdt->name);
+ PQerrorMessage(pgdt->pgconn), &pgdt->name);
dd("returning NGX_ERROR");
return NGX_ERROR;
@@ -233,7 +233,7 @@ ngx_postgres_upstream_send_query(ngx_http_request_t *r, ngx_connection_t *pgxc,
dd("sending query failed");
ngx_log_error(NGX_LOG_ERR, pgxc->log, 0,
"postgres: sending query failed: %s in upstream \"%V\"",
- PQerrorMessage(pgdt->pgconn), pgdt->name);
+ PQerrorMessage(pgdt->pgconn), &pgdt->name);
dd("returning NGX_ERROR");
return NGX_ERROR;
@@ -283,7 +283,7 @@ ngx_postgres_upstream_get_result(ngx_http_request_t *r, ngx_connection_t *pgxc,
dd("receiving result failed");
ngx_log_error(NGX_LOG_ERR, pgxc->log, 0,
"postgres: receiving result failed: %s in upstream"
- " \"%V\"", PQerrorMessage(pgdt->pgconn), pgdt->name);
+ " \"%V\"", PQerrorMessage(pgdt->pgconn), &pgdt->name);
dd("returning NGX_ERROR");
return NGX_ERROR;
@@ -295,7 +295,7 @@ ngx_postgres_upstream_get_result(ngx_http_request_t *r, ngx_connection_t *pgxc,
ngx_log_error(NGX_LOG_ERR, pgxc->log, 0,
"postgres: receiving result failed: %s: %s in upstream"
" \"%V\"", PQresStatus(pgrc),
- PQerrorMessage(pgdt->pgconn), pgdt->name);
+ PQerrorMessage(pgdt->pgconn), &pgdt->name);
PQclear(res);
@@ -429,7 +429,7 @@ ngx_postgres_upstream_get_ack(ngx_http_request_t *r, ngx_connection_t *pgxc,
dd("receiving ACK failed");
ngx_log_error(NGX_LOG_ERR, pgxc->log, 0,
"postgres: receiving ACK failed: multiple queries(?),"
- " in upstream \"%V\"", pgdt->name);
+ " in upstream \"%V\"", &pgdt->name);
PQclear(res);
View
9 src/ngx_postgres_upstream.c
@@ -280,10 +280,13 @@ ngx_postgres_upstream_get_peer(ngx_peer_connection_t *pc, void *data)
peer = &peers->peer[pgscf->current++];
- pgdt->name = &peer->name;
+ pgdt->name.len = peer->name.len;
+ pgdt->name.data = peer->name.data;
- pc->name = &peer->name;
- pc->sockaddr = peer->sockaddr;
+ pgdt->sockaddr = *peer->sockaddr;
+
+ pc->name = &pgdt->name;
+ pc->sockaddr = &pgdt->sockaddr;
pc->socklen = peer->socklen;
pc->cached = 0;
View
6 src/ngx_postgres_upstream.h
@@ -52,8 +52,9 @@ typedef struct {
PGconn *pgconn;
ngx_postgres_state_t state;
ngx_str_t query;
- ngx_str_t *name;
- ngx_flag_t failed;
+ ngx_str_t name;
+ struct sockaddr sockaddr;
+ unsigned failed;
} ngx_postgres_upstream_peer_data_t;
@@ -69,4 +70,5 @@ void ngx_postgres_upstream_free_connection(ngx_log_t *,
ngx_connection_t *, PGconn *,
ngx_postgres_upstream_srv_conf_t *);
+
#endif /* _NGX_HTTP_UPSTREAM_POSTGRES_H_ */
Please sign in to comment.
Something went wrong with that request. Please try again.