You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
sendEmail invokes defer res.Body.Close() in a naked for-loop but those only get invoked when the function is returning; many emails could cause resource exhaustion
#13
Open
odeke-em opened this issue
Mar 20, 2024
· 0 comments
· May be fixed by #14
The surrounding function in this case is sendEmail
This means that those response handles won't be closed until the for loop is done (if there are many emails to be sent, this could cause resource exhaustion problems)
Fix
We can extract that code into a per-email helper function and even better we can rename the calling function from "sendEmail" to "sendEmails" to signify the purpose, and the extracted code would look like this in a diff
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.
Fixescds-snc#13
Noticed in a quick code audit that we've got this code
smtp-proxy-for-notify/notify_client.go
Lines 95 to 102 in b893964
The surrounding function in this case is sendEmail
This means that those response handles won't be closed until the for loop is done (if there are many emails to be sent, this could cause resource exhaustion problems)
Fix
We can extract that code into a per-email helper function and even better we can rename the calling function from "sendEmail" to "sendEmails" to signify the purpose, and the extracted code would look like this in a diff
The text was updated successfully, but these errors were encountered: