Skip to content

Commit b3470c5

Browse files
authored
Merge pull request #4 from polarismesh/hotfix/fix_coredump
fix coredump
2 parents 8a8e3f0 + 1ed345e commit b3470c5

File tree

2 files changed

+6
-26
lines changed

2 files changed

+6
-26
lines changed

nginx_polaris_module/ngx_http_upstream_polaris_module.cpp

Lines changed: 6 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -205,9 +205,6 @@ static ngx_int_t ngx_http_upstream_init_polaris_peer(ngx_http_request_t *r,
205205
r->upstream->peer.get = ngx_http_upstream_get_polaris_peer;
206206
r->upstream->peer.free = ngx_http_upstream_free_polaris_peer;
207207

208-
if (dcf->max_tries != NGX_CONF_UNSET_UINT) {
209-
r->upstream->peer.tries = dcf->max_tries;
210-
}
211208
// control the retry times >= 2.
212209
if (r->upstream->peer.tries < 2) {
213210
r->upstream->peer.tries = 2;
@@ -227,7 +224,6 @@ static ngx_int_t ngx_http_upstream_init_polaris_peer(ngx_http_request_t *r,
227224

228225
memset(ctx, 0, sizeof(ngx_http_upstream_polaris_ctx_t));
229226
ngx_http_set_ctx(r, ctx, ngx_http_upstream_polaris_module);
230-
dp->ctx = ctx;
231227
}
232228

233229
if (polaris_init_params(dcf, r, ctx) != NGX_OK) {
@@ -251,7 +247,8 @@ static ngx_int_t ngx_http_upstream_get_polaris_peer(ngx_peer_connection_t *pc, v
251247
pc->cached = 0;
252248
pc->connection = NULL;
253249

254-
ngx_http_upstream_polaris_ctx_t *ctx = bp->ctx;
250+
ngx_http_upstream_polaris_ctx_t *ctx = reinterpret_cast<ngx_http_upstream_polaris_ctx_t *>(
251+
ngx_http_get_module_ctx(r, ngx_http_upstream_polaris_module));
255252

256253
int ret = polaris_get_addr(ctx);
257254

@@ -283,7 +280,8 @@ static void ngx_http_upstream_free_polaris_peer(ngx_peer_connection_t *pc, void
283280

284281
ngx_log_debug(NGX_LOG_DEBUG_HTTP, pc->log, 0, "free polaris peer state:%d", state);
285282

286-
ngx_http_upstream_polaris_ctx_t *ctx = bp->ctx;
283+
ngx_http_upstream_polaris_ctx_t *ctx = reinterpret_cast<ngx_http_upstream_polaris_ctx_t *>(
284+
ngx_http_get_module_ctx(bp->request, ngx_http_upstream_polaris_module));
287285

288286
ngx_log_debug(NGX_LOG_DEBUG_HTTP, pc->log, 0, "free polaris peer ret status code: %d",
289287
bp->request->headers_out.status);
@@ -343,7 +341,6 @@ static void *ngx_http_upstream_polaris_create_conf(ngx_conf_t *cf) {
343341
conf->polaris_metadata_route_enabled = false;
344342
ngx_str_set(&conf->polaris_fail_status_list, "");
345343
conf->polaris_fail_status_report_enabled = false;
346-
conf->max_tries = NGX_CONF_UNSET_UINT;
347344

348345
return conf;
349346
}
@@ -588,20 +585,6 @@ static char *ngx_http_upstream_polaris_set_handler(ngx_conf_t *cf, ngx_command_t
588585

589586
continue;
590587
}
591-
592-
if (ngx_strncmp(value[i].data, "max_tries=", 10) == 0) {
593-
ngx_str_t s = {value[i].len - 10, &value[i].data[10]};
594-
595-
ngx_int_t max_tries = ngx_atoi(s.data, s.len);
596-
if (max_tries < 1 || max_tries > 256) {
597-
ngx_conf_log_error(NGX_LOG_ERR, cf, 0,
598-
"dcf->max_tries:%d invalid, only valid in (1-256)",
599-
max_tries);
600-
return const_cast<char *>("invalid polaris max_tries");
601-
}
602-
dcf->max_tries = max_tries;
603-
continue;
604-
}
605588
}
606589

607590
dcf->enabled = true;
@@ -663,10 +646,10 @@ static char *ngx_http_upstream_polaris_set_handler(ngx_conf_t *cf, ngx_command_t
663646
ngx_conf_log_error(
664647
NGX_LOG_NOTICE, cf, 0,
665648
"init service_namespace:%s, service_name:%s, timeout: %.2f, mode: %d, "
666-
"key: %s, dr: %d, mr_mode: %d, fail_status: %s, max_tries: %d",
649+
"key: %s, dr: %d, mr_mode: %d, fail_status: %s",
667650
dcf->polaris_service_namespace.data, dcf->polaris_service_name.data, dcf->polaris_timeout,
668651
dcf->polaris_lb_mode, dcf->polaris_lb_key.data, dcf->polaris_dynamic_route_enabled,
669-
dcf->metadata_route_failover_mode, dcf->polaris_fail_status_list.data, dcf->max_tries);
652+
dcf->metadata_route_failover_mode, dcf->polaris_fail_status_list.data);
670653

671654
return NGX_CONF_OK;
672655
}

nginx_polaris_module/ngx_http_upstream_polaris_module.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,8 +62,6 @@ typedef struct {
6262

6363
ngx_http_upstream_init_pt original_init_upstream;
6464
ngx_http_upstream_init_peer_pt original_init_peer;
65-
66-
ngx_uint_t max_tries;
6765
} ngx_http_upstream_polaris_srv_conf_t;
6866

6967
/**
@@ -108,7 +106,6 @@ typedef struct {
108106
ngx_http_request_t *request;
109107
ngx_event_get_peer_pt original_get_peer;
110108
ngx_event_free_peer_pt original_free_peer;
111-
ngx_http_upstream_polaris_ctx_t *ctx;
112109
} ngx_http_upstream_polaris_peer_data_t;
113110

114111
extern "C" ngx_module_t ngx_http_upstream_polaris_module;

0 commit comments

Comments
 (0)