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

Safer HTTP client initialization and usage. #458

Merged
merged 2 commits into from
Feb 9, 2022

Conversation

dobs
Copy link
Contributor

@dobs dobs commented Feb 8, 2022

This PR has two major components (corresponding to the two commits):

  • Updating API client creation to only initialize once rather than every time a client is referenced.
  • Surfacing client errors whenever an API client is retrieved from the config.

By exposing new errors this change may break some expectations around what errors might be returned by the provider, but hopefully in a way that's useful (i.e. before it would segfault, now it'll hopefully return something more informative).

The one gotcha would be if client re-initialization was intentional, but hopefully that isn't the case. And one optimization might be to explicitly initialize the client at config time, after which we don't need error handling around Client() calls.

This PR likely addresses the segfaults mentioned in issues:

dobs added 2 commits February 8, 2022 12:41
REST and Slack clients are now only initialized if they haven't already,
plus are initialized with a lock on the configuration to avoid
contention cases.

One notably improvement is that this saves us from validating auth every
time the REST client is referenced.
Hopefully this provides more visibiility into cases where a legitimate
error interferes with client creation.
@dobs dobs requested a review from stmcallister February 8, 2022 18:45
Comment on lines +51 to +52
c.mu.Lock()
defer c.mu.Unlock()
Copy link

@gempesaw gempesaw Feb 8, 2022

Choose a reason for hiding this comment

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

haven't used mutexes before in Go, but pleasantly surprised how simple this looks! that's all it takes to handle "a bunch of different callers ask for a client at the same time, and we only want to make one, and have all my callers wait until i make that and give the single one to everyone" ? :o cooool

Copy link
Contributor

@stmcallister stmcallister left a comment

Choose a reason for hiding this comment

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

Thanks @dobs !! I think this will be a great improvement to user experience.

@stmcallister stmcallister merged commit 661767b into PagerDuty:master Feb 9, 2022
@NargiT
Copy link
Contributor

NargiT commented Feb 11, 2022

Amazing ! Thanks I will test this because I had to rollback to 1.x.

@dobs
Copy link
Contributor Author

dobs commented Feb 11, 2022

@NargiT Great! Let us know whether it resolves the issue you encountered.

One thing to call out is that these segmentation faults could be a result of some other underlying error (e.g. rate limiting), but hopefully this change will at least make those errors more actionable.

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.

4 participants