Skip to content

not all exceptions being caught #212

@jsamuel

Description

@jsamuel

I see cases where exceptions aren't being caught from calls to increment() and other stats reporting functions. According to the code, it's only catching socket.error but there are other errors that can happen, at least in multithreaded applications.

  File "/opt/python3.6/lib/python3.6/site-packages/datadog/dogstatsd/base.py", line 153, in increment
    self._report(metric, 'c', value, tags, sample_rate)
  File "/opt/python3.6/lib/python3.6/site-packages/datadog/dogstatsd/base.py", line 262, in _report
    self._send(encoded)
  File "/opt/python3.6/lib/python3.6/site-packages/datadog/dogstatsd/base.py", line 267, in _send_to_server
    (self.socket or self.get_socket()).send(packet.encode(self.encoding))
AttributeError: 'NoneType' object has no attribute 'send'

I think you should be catching every exception and never letting an exception escape from your code. Otherwise, these types of bugs in dogstats can cause bugs in people's applications if they are using dogstats. As it stands, it looks like the only safe usage appears to be to write a wrapper around dogstats calls to make sure they can never raise exceptions.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions