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

fix: properly close HTTP responses after sending each email #14

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

odeke-em
Copy link

This change extracts per-email sending logic into a helper function for which proper resource closing can be performed. Previously it invoke defer res.Body.Close in a for-loop but Go's specifications and operations dictate that the defer will only be invoked when the surrounding function is returning or panicking: this means then that if very many emails are being sent, that risks potential resource exhaustion because so many connections won't be closed yet nor can they be garbage collected.

Fixes #13

This change extracts per-email sending logic into a helper function
for which proper resource closing can be performed. Previously it
invoke defer res.Body.Close in a for-loop but Go's specifications
and operations dictate that the defer will only be invoked when
the surrounding function is returning or panicking: this means then
that if very many emails are being sent, that risks potential
resource exhaustion because so many connections won't be closed yet
nor can they be garbage collected.

Fixes cds-snc#13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
1 participant