Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

when dns resolve update, because server addr maybe changed, hence we may get the wrong $upstream_addr http variable #86

Open
leeweishi opened this issue May 21, 2024 · 0 comments

Comments

@leeweishi
Copy link

we need to save the server addr somewhere else, just like below

static ngx_int_t
ngx_http_upstream_get_jdomain_peer(ngx_peer_connection_t *pc,
void *data)
{
ngx_http_upstream_jdomain_peer_data_t *jp = data;
ngx_http_request_t *r;
ngx_http_upstream_t *u;
ngx_int_t rc;

ngx_str_t                             *addr;
u_char                                *p;

size_t                                 len;

ngx_log_debug0(NGX_LOG_DEBUG_HTTP, pc->log, 0,
           "get jdomain peer");

rc = jp->original_get_peer(pc, jp->data);

if (rc != NGX_OK) {
    return rc;
}

r = jp->request;
u = r->upstream;

len = pc->name->len;
p = ngx_pnalloc(r->pool, len);
if (p == NULL) {
    return NGX_ERROR;
}

ngx_memcpy(p, pc->name->data, len);

addr = ngx_palloc(r->pool, sizeof(ngx_str_t));
if (addr == NULL) {
    return NGX_ERROR;
}

addr->data = p;
addr->len = len;
pc->name = addr;

return NGX_OK;

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant