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

Found udp_connection to be null when statsd server is not available #5

Open
janmejay opened this issue Jan 17, 2014 · 1 comment
Open

Comments

@janmejay
Copy link

ngx_http_statsd_udp_send calls uc->connection and when uc is null it generates segfault.

Here is the trace:

Program received signal SIGSEGV, Segmentation fault.
0x00000000004c1301 in ngx_http_statsd_udp_send (l=0xf54590,
    buf=0xfb98a8 "retail.pricing.fk_proxy.ip_10_98_169_234.80.status.200:1|c\003\243FB\a\356\001", len=58) at ../nginx-statsd/ngx_http_statsd.c:382
382     ../nginx-statsd/ngx_http_statsd.c: No such file or directory.
        in ../nginx-statsd/ngx_http_statsd.c
(gdb) bt
#0  0x00000000004c1301 in ngx_http_statsd_udp_send (l=0xf54590,
    buf=0xfb98a8 "retail.pricing.fk_proxy.ip_10_98_169_234.80.status.200:1|c\003\243FB\a\356\001", len=58) at ../nginx-statsd/ngx_http_statsd.c:382
#1  0x00000000004c10a2 in ngx_http_statsd_handler (r=0xf45960) at ../nginx-statsd/ngx_http_statsd.c:313
#2  0x000000000045c465 in ngx_http_log_request (r=0xf45960) at src/http/ngx_http_request.c:3455
#3  0x000000000045c2d6 in ngx_http_free_request (r=0xf45960, rc=0) at src/http/ngx_http_request.c:3402
#4  0x000000000045af7b in ngx_http_set_keepalive (r=0xf45960) at src/http/ngx_http_request.c:2840
#5  0x000000000045a3f5 in ngx_http_finalize_connection (r=0xf45960) at src/http/ngx_http_request.c:2483
#6  0x000000000045a058 in ngx_http_finalize_request (r=0xf45960, rc=0) at src/http/ngx_http_request.c:2384
#7  0x0000000000477feb in ngx_http_upstream_finalize_request (r=0xf45960, u=0xfb66f0, rc=0) at src/http/ngx_http_upstream.c:3560
#8  0x00000000004770eb in ngx_http_upstream_process_request (r=0xf45960) at src/http/ngx_http_upstream.c:3161
#9  0x0000000000476e08 in ngx_http_upstream_process_upstream (r=0xf45960, u=0xfb66f0) at src/http/ngx_http_upstream.c:3092
#10 0x00000000004721db in ngx_http_upstream_handler (ev=0x1005230) at src/http/ngx_http_upstream.c:977
#11 0x000000000043b78e in ngx_epoll_process_events (cycle=0xf38620, timer=60000, flags=1) at src/event/modules/ngx_epoll_module.c:691
#12 0x000000000042bfd4 in ngx_process_events_and_timers (cycle=0xf38620) at src/event/ngx_event.c:248
#13 0x0000000000439696 in ngx_worker_process_cycle (cycle=0xf38620, data=0x0) at src/os/unix/ngx_process_cycle.c:816
#14 0x0000000000435ef6 in ngx_spawn_process (cycle=0xf38620, proc=0x439490 , data=0x0, name=0x4c69c3 "worker process",
    respawn=0) at src/os/unix/ngx_process.c:198
#15 0x0000000000439089 in ngx_reap_children (cycle=0xf38620) at src/os/unix/ngx_process_cycle.c:627
#16 0x0000000000437d19 in ngx_master_process_cycle (cycle=0xf38620) at src/os/unix/ngx_process_cycle.c:180
#17 0x000000000040727f in main (argc=1, argv=0x7fffd7f4cee8) at src/core/nginx.c:407
@janmejay
Copy link
Author

Added a null check to fix it, here is the patch.

Please advice if there is a better way of fixing this.

From 7105230479ed6ee89371bae2d6655429c9efa515 Mon Sep 17 00:00:00 2001
From: Janmejay Singh 
Date: Fri, 17 Jan 2014 16:12:55 +0530
Subject: [PATCH] check that udp_connection exists before trying
 to use it, absense of this segfaults the worker
---
 ngx_http_statsd.c | 3 +++
 1 file changed, 3 insertions(+)
diff --git a/ngx_http_statsd.c b/ngx_http_statsd.c
index c2f1041..939ce43 100644
--- a/ngx_http_statsd.c
+++ b/ngx_http_statsd.c
@@ -379,6 +379,9 @@ ngx_http_statsd_udp_send(ngx_udp_endpoint_t *l, u_char *buf, size_t len)
     ngx_udp_connection_t  *uc;
 
     uc = l->udp_connection;
+    if (! uc) {
+        return NGX_ERROR;
+    }
     if (uc->connection == NULL) {
 
         uc->log = *l->log;
-- 
1.8.3.2

antineutron pushed a commit to antineutron/nginx-dogstatsd that referenced this issue Mar 16, 2018
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