Skip to content

Commit

Permalink
agents: fix crash in StatsDAgent
Browse files Browse the repository at this point in the history
With some specific udp send errors, it's not possible to retrieve the
peername. Handle this case to avoid crashes.

Fixes: #31
  • Loading branch information
santigimeno committed Nov 23, 2023
1 parent f16e228 commit cf1a376
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions agents/statsd/src/statsd_agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,13 @@ void StatsDUdp::write_cb_(nsuv::ns_udp_send* req, int status, StatsDUdp* udp) {
struct sockaddr_storage ss;
struct sockaddr* addr = reinterpret_cast<struct sockaddr*>(&ss);
int len = sizeof(ss);
ASSERT_EQ(0, uv_udp_getpeername(req->handle(), addr, &len));
Debug("Error '%s' sending data to: %s.\n",
uv_err_name(status), addr_to_string(addr).c_str());
int r = uv_udp_getpeername(req->handle(), addr, &len);
if (r == 0) {
Debug("Error '%s' sending data to: %s.\n",
uv_err_name(status), addr_to_string(addr).c_str());
} else {
Debug("Error '%s' sending data to\n", uv_err_name(status));
}
}

udp_req_data_tup* req_data = req->get_data<udp_req_data_tup>();
Expand Down

0 comments on commit cf1a376

Please sign in to comment.