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

Fixing context cancelled for webhook post calls #399

Merged
merged 9 commits into from
May 8, 2023
Merged

Conversation

nitro-neal
Copy link
Contributor

Overview

Fixes an issue where we would get cancelled contexts for webhook calls

@codecov-commenter
Copy link

codecov-commenter commented May 3, 2023

Codecov Report

Merging #399 (f70ab05) into main (44f9064) will decrease coverage by 0.01%.
The diff coverage is 0.00%.

@@            Coverage Diff             @@
##             main     #399      +/-   ##
==========================================
- Coverage   20.43%   20.43%   -0.01%     
==========================================
  Files          48       48              
  Lines        5422     5423       +1     
==========================================
  Hits         1108     1108              
- Misses       4139     4140       +1     
  Partials      175      175              
Impacted Files Coverage Δ
config/config.go 16.45% <0.00%> (-0.11%) ⬇️

@@ -191,9 +192,9 @@ func (s Service) PublishWebhook(ctx context.Context, noun Noun, verb Verb, paylo
continue
}

err = s.post(ctx, url, string(postJSONData))
err = s.post(context.Background(), url, string(postJSONData))
Copy link
Contributor

Choose a reason for hiding this comment

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

context.Background mean that this call can wait forever. This can lead to memory increasing without a bound.

Instead, I suggest to us some cancellable context.

config/config.toml Outdated Show resolved Hide resolved
pkg/service/webhook/service.go Outdated Show resolved Hide resolved
return
}
ctx, cancel := context.WithTimeout(context.Background(), duration)
defer cancel()
err = s.post(ctx, url, string(postJSONData))
Copy link
Member

Choose a reason for hiding this comment

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

can combine with the line below

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This has changed locatoin

Copy link
Contributor

@andresuribe87 andresuribe87 left a comment

Choose a reason for hiding this comment

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

Awesome! Couple of small nits.

pkg/service/webhook/service.go Outdated Show resolved Hide resolved
pkg/service/webhook/service.go Outdated Show resolved Hide resolved
@nitro-neal nitro-neal merged commit 2dbfc4d into main May 8, 2023
@nitro-neal nitro-neal deleted the webhook-context branch May 8, 2023 16:38
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