Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

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
Yichun Zhang authored February 17, 2011
18  src/ngx_postgres_keepalive.c
@@ -85,13 +85,17 @@ ngx_postgres_keepalive_get_peer_single(ngx_peer_connection_t *pc,
85 85
         c->read->log = pc->log;
86 86
         c->write->log = pc->log;
87 87
 
88  
-        pc->connection = c;
89  
-        pc->cached = 1;
90  
-
91 88
         pgp->name = &item->name;
92 89
         pgp->pgconn = item->pgconn;
93 90
 
  91
+        pc->connection = c;
  92
+        pc->cached = 1;
  93
+        pc->name = pgp->name;
  94
+        pc->sockaddr = &item->sockaddr;
  95
+        pc->socklen = item->socklen;
  96
+
94 97
         dd("returning NGX_DONE");
  98
+
95 99
         return NGX_DONE;
96 100
     }
97 101
 
@@ -186,6 +190,7 @@ ngx_postgres_keepalive_free_peer(ngx_peer_connection_t *pc,
186 190
 
187 191
             ngx_postgres_upstream_free_connection(pc->log, item->connection,
188 192
                                                   item->pgconn, pgscf);
  193
+
189 194
         } else {
190 195
             q = ngx_queue_head(&pgscf->free);
191 196
             ngx_queue_remove(q);
@@ -216,10 +221,13 @@ ngx_postgres_keepalive_free_peer(ngx_peer_connection_t *pc,
216 221
         c->read->log = ngx_cycle->log;
217 222
         c->write->log = ngx_cycle->log;
218 223
 
219  
-        item->socklen = pc->socklen;
220  
-        ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen);
  224
+        if (pc->sockaddr != &item->sockaddr) {
  225
+            item->socklen = pc->socklen;
  226
+            ngx_memcpy(&item->sockaddr, pc->sockaddr, pc->socklen);
  227
+        }
221 228
 
222 229
         item->pgconn = pgp->pgconn;
  230
+        item->name = *pgp->name;
223 231
     }
224 232
 
225 233
     dd("returning");
2  src/ngx_postgres_keepalive.h
@@ -41,7 +41,7 @@ typedef struct {
41 41
     ngx_postgres_upstream_srv_conf_t  *srv_conf;
42 42
     ngx_connection_t                  *connection;
43 43
     PGconn                            *pgconn;
44  
-    struct sockaddr_storage            sockaddr;
  44
+    struct sockaddr                    sockaddr;
45 45
     socklen_t                          socklen;
46 46
     ngx_str_t                          name;
47 47
 } ngx_postgres_keepalive_cache_t;

0 notes on commit 5dd0c57

Please sign in to comment.
Something went wrong with that request. Please try again.