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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't allow package version to be None #1380

Merged
merged 2 commits into from
May 4, 2020
Merged

Conversation

Kyle-Verhoog
Copy link
Member

@Kyle-Verhoog Kyle-Verhoog commented Apr 23, 2020

If users try to repackage the library there is the possibility that the __version__ can be None which eventually causes the writer to fail as it tries to serialize None into the http headers sent to the agent.

This PR provides a more sensible default.

thanks to @thehesiod for finding and describing this error 馃檪.

@Kyle-Verhoog Kyle-Verhoog requested a review from a team as a code owner April 23, 2020 20:09
@thehesiod
Copy link
Contributor

thank you!

@brettlangdon
Copy link
Member

hmm, when does this happen?

brettlangdon
brettlangdon previously approved these changes Apr 23, 2020
@Kyle-Verhoog
Copy link
Member Author

Kyle-Verhoog commented Apr 23, 2020

@brettlangdon it was occurring in @thehesiod's case in a pretty niche situation where the version would be None as a result of

try:
__version__ = pkg_resources.get_distribution(__name__).version
except pkg_resources.DistributionNotFound:
# package is not installed
__version__ = None

which would then be used here*:

'Datadog-Meta-Tracer-Version': ddtrace.__version__,

* edited to correct the line

@brettlangdon
Copy link
Member

Makes sense, that is off scenario, but possible.

aside: I wonder if we should default to "dev" instead of None /cc @jd

brettlangdon
brettlangdon previously approved these changes Apr 23, 2020
Copy link
Contributor

@jd jd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just one question: the reason you were able to fix that headers issue is because the Exception base class is not caught.

You're now hiding that bug under the carpet IIUC.

I don't see how it's wise?

If you want the writer thread to be robust to crash, you should handle a general try/except Exception at its root that makes it restart on handled exception. Using except Exception everywhere and hiding issues is not goint to help us in the long run.

@Kyle-Verhoog
Copy link
Member Author

@jd agreed. But you're proposing a larger refactoring change (which I totally agree with). This is correction to existing code that, from what I can tell, assumed that it was catching all possible exceptions that could be raised and it wasn't.

Given the way the current code is structured I think it makes sense. I also don't like it either. A larger change to this code will take longer to review/get merged whereas this addresses the problem immediately without introducing any new "badness" that was not already there 馃槢.

Exception code aside, I think it does make sense to change the default for version to be, at least, not None.

Your thoughts? 馃檪

@jd
Copy link
Contributor

jd commented Apr 27, 2020

The problem is that I think the medicine is worse than the illness: this is not going to fix the illness, it's going to hide it, and worse, hide future ones!

I'm not asking for a large refactoring. I'm stating the current behavior is sane. What should be fixed is:

  1. the header that is None should be fixed (Brett proposed a solution for this)
  2. if we want to make the code more robust we shouldn't do what this PR does but make the worker thread restart-on-crash (I hope it's not a large refactoring!)

@Kyle-Verhoog
Copy link
Member Author

Fair enough 馃檪. The real issue at hand here is that a header can be None so let's correct that. I've got some changes in the pipeline for how the worker deals with exceptions so we can revisit the design there.

@Kyle-Verhoog Kyle-Verhoog changed the title fix(api): handle all exceptions from http request fix: don't allow package version to be None May 2, 2020
@thehesiod
Copy link
Contributor

in general assuming what errors can occur from a global error handler is bad policy, especially w/o any sort of logging that errors are uncaught since it causes the thread to go away

@Kyle-Verhoog Kyle-Verhoog merged commit d0aeecb into master May 4, 2020
@Kyle-Verhoog Kyle-Verhoog deleted the kylev/api_exc branch May 4, 2020 14:53
@Kyle-Verhoog Kyle-Verhoog added this to the 0.37.1 milestone May 12, 2020
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

Successfully merging this pull request may close these issues.

None yet

4 participants