Skip to content

Commit

Permalink
Upstream: fixed "no port" detection in evaluated upstreams.
Browse files Browse the repository at this point in the history
If an upstream with variables evaluated to address without a port,
then instead of a "no port in upstream" error an attempt was made
to connect() which failed with EADDRNOTAVAIL.
  • Loading branch information
mdocguard committed Nov 21, 2015
1 parent cb53069 commit 72b9a31
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 10 deletions.
5 changes: 3 additions & 2 deletions src/http/modules/ngx_http_fastcgi_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -773,10 +773,11 @@ ngx_http_fastcgi_eval(ngx_http_request_t *r, ngx_http_fastcgi_loc_conf_t *flcf)

} else {
u->resolved->host = url.host;
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;
}

u->resolved->port = url.port;
u->resolved->no_port = url.no_port;

return NGX_OK;
}

Expand Down
5 changes: 3 additions & 2 deletions src/http/modules/ngx_http_proxy_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -1015,10 +1015,11 @@ ngx_http_proxy_eval(ngx_http_request_t *r, ngx_http_proxy_ctx_t *ctx,

} else {
u->resolved->host = url.host;
u->resolved->port = (in_port_t) (url.no_port ? port : url.port);
u->resolved->no_port = url.no_port;
}

u->resolved->port = (in_port_t) (url.no_port ? port : url.port);
u->resolved->no_port = url.no_port;

return NGX_OK;
}

Expand Down
5 changes: 3 additions & 2 deletions src/http/modules/ngx_http_scgi_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -569,10 +569,11 @@ ngx_http_scgi_eval(ngx_http_request_t *r, ngx_http_scgi_loc_conf_t * scf)

} else {
u->resolved->host = url.host;
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;
}

u->resolved->port = url.port;
u->resolved->no_port = url.no_port;

return NGX_OK;
}

Expand Down
5 changes: 3 additions & 2 deletions src/http/modules/ngx_http_uwsgi_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -771,10 +771,11 @@ ngx_http_uwsgi_eval(ngx_http_request_t *r, ngx_http_uwsgi_loc_conf_t * uwcf)

} else {
u->resolved->host = url.host;
u->resolved->port = url.port;
u->resolved->no_port = url.no_port;
}

u->resolved->port = url.port;
u->resolved->no_port = url.no_port;

return NGX_OK;
}

Expand Down
12 changes: 10 additions & 2 deletions src/http/ngx_http_upstream.c
Original file line number Diff line number Diff line change
Expand Up @@ -633,8 +633,18 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
u->ssl_name = u->resolved->host;
#endif

host = &u->resolved->host;

if (u->resolved->sockaddr) {

if (u->resolved->port == 0) {
ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
"no port in upstream \"%V\"", host);
ngx_http_upstream_finalize_request(r, u,
NGX_HTTP_INTERNAL_SERVER_ERROR);
return;
}

if (ngx_http_upstream_create_round_robin_peer(r, u->resolved)
!= NGX_OK)
{
Expand All @@ -648,8 +658,6 @@ ngx_http_upstream_init_request(ngx_http_request_t *r)
return;
}

host = &u->resolved->host;

umcf = ngx_http_get_module_main_conf(r, ngx_http_upstream_module);

uscfp = umcf->upstreams.elts;
Expand Down

0 comments on commit 72b9a31

Please sign in to comment.