Skip to content

Commit 02ce447

Browse files
committed
Fixed Nginx CPU 100% usage issue
1 parent 90c5060 commit 02ce447

File tree

2 files changed

+14
-6
lines changed

2 files changed

+14
-6
lines changed

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
MIT License
22

3-
Copyright (c) 2021 IP2Location.com
3+
Copyright (c) 2022 IP2Location.com
44

55
Permission is hereby granted, free of charge, to any person obtaining a copy
66
of this software and associated documentation files (the "Software"), to deal

ngx_http_ip2proxy.c

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ static char *ngx_http_ip2proxy_database(ngx_conf_t *cf, ngx_command_t *cmd, void
3131
static char *ngx_http_ip2proxy_proxy(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
3232
static ngx_int_t ngx_http_ip2proxy_cidr_value(ngx_conf_t *cf, ngx_str_t *net, ngx_cidr_t *cidr);
3333
static void ngx_http_ip2proxy_cleanup(void *data);
34+
static IP2Proxy *ip2proxy_bin_handler;
3435

3536
static ngx_command_t ngx_http_ip2proxy_commands[] = {
3637
{
@@ -345,6 +346,12 @@ ngx_http_ip2proxy_database(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
345346
return "Duplicated";
346347
}
347348

349+
if (ip2proxy_bin_handler){
350+
//close the bin if it's still opened
351+
IP2Proxy_close(ip2proxy_bin_handler);
352+
ip2proxy_bin_handler = NULL;
353+
}
354+
348355
value = cf->args->elts;
349356

350357
if (value[1].len == 0) {
@@ -354,6 +361,7 @@ ngx_http_ip2proxy_database(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
354361

355362
// Open IP2Proxy BIN database
356363
gcf->handler = IP2Proxy_open((char *) value[1].data);
364+
ip2proxy_bin_handler = gcf->handler;
357365

358366
if (gcf->handler == NULL) {
359367
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "Unable to open database file \"%s\".", &value[1].data);
@@ -426,10 +434,10 @@ ngx_http_ip2proxy_cidr_value(ngx_conf_t *cf, ngx_str_t *net, ngx_cidr_t *cidr)
426434
static void
427435
ngx_http_ip2proxy_cleanup(void *data)
428436
{
429-
ngx_http_ip2proxy_conf_t *gcf = data;
437+
//ngx_http_ip2proxy_conf_t *gcf = data;
430438

431-
if (gcf->handler) {
432-
IP2Proxy_close(gcf->handler);
433-
gcf->handler = NULL;
434-
}
439+
// if (gcf->handler) {
440+
// IP2Proxy_close(gcf->handler);
441+
// gcf->handler = NULL;
442+
// }
435443
}

0 commit comments

Comments
 (0)