Skip to content

Commit

Permalink
Fixed Nginx CPU 100% usage issue
Browse files Browse the repository at this point in the history
  • Loading branch information
ip2location committed Nov 9, 2022
1 parent 5bcb9f1 commit 2df35fb
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
Refer to https://github.com/ip2location/ip2location-nginx to release notes.

nginx-ip2location-8.1.1
=======================
Fixed Nginx CPU 100% usage issue.

nginx-ip2location-8.1.0
=======================
Ported codes from https://github.com/chaizhenhua/ngx-ip2location to support all fields in IP2Location database.
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
MIT License

Copyright (c) 2021 IP2Location.com
Copyright (c) 2022 IP2Location.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
18 changes: 13 additions & 5 deletions ngx_http_ip2location_module.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ static char *ngx_http_ip2location_database(ngx_conf_t *cf, ngx_command_t *cmd, v
static char *ngx_http_ip2location_proxy(ngx_conf_t *cf, ngx_command_t *cmd, void *conf);
static ngx_int_t ngx_http_ip2location_cidr_value(ngx_conf_t *cf, ngx_str_t *net, ngx_cidr_t *cidr);
static void ngx_http_ip2location_cleanup(void *data);
static IP2Location *ip2location_bin_handler;

static ngx_command_t ngx_http_ip2location_commands[] = {
{
Expand Down Expand Up @@ -426,6 +427,12 @@ ngx_http_ip2location_database(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)
return "Duplicated";
}

if (ip2location_bin_handler){
//close the bin if it's still opened
IP2Location_close(ip2location_bin_handler);
ip2location_bin_handler = NULL;
}

value = cf->args->elts;

if (value[1].len == 0) {
Expand All @@ -435,6 +442,7 @@ ngx_http_ip2location_database(ngx_conf_t *cf, ngx_command_t *cmd, void *conf)

// Open IP2Location BIN database
gcf->handler = IP2Location_open((char *) value[1].data);
ip2location_bin_handler = gcf->handler;

if (gcf->handler == NULL) {
ngx_conf_log_error(NGX_LOG_EMERG, cf, 0, "Unable to open database file \"%s\".", value[1].data);
Expand Down Expand Up @@ -509,10 +517,10 @@ ngx_http_ip2location_cidr_value(ngx_conf_t *cf, ngx_str_t *net, ngx_cidr_t *cidr
static void
ngx_http_ip2location_cleanup(void *data)
{
ngx_http_ip2location_conf_t *gcf = data;
//ngx_http_ip2location_conf_t *gcf = data;

if (gcf->handler) {
IP2Location_close(gcf->handler);
gcf->handler = NULL;
}
// if (gcf->handler) {
// IP2Location_close(gcf->handler);
// gcf->handler = NULL;
// }
}

0 comments on commit 2df35fb

Please sign in to comment.