Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0f414a0

Browse files
authored
fix: restore closing SMTP message on method exit (#14496)
1 parenta74273f commit0f414a0

File tree

1 file changed

+10
-1
lines changed
  • coderd/notifications/dispatch

1 file changed

+10
-1
lines changed

‎coderd/notifications/dispatch/smtp.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,15 @@ func (s *SMTPHandler) dispatch(subject, htmlBody, plainBody, to string) Delivery
183183
iferr!=nil {
184184
returntrue,xerrors.Errorf("message transmission: %w",err)
185185
}
186+
closeOnce:=sync.OnceValue(func()error {
187+
returnmessage.Close()
188+
})
189+
// Close the message when this method exits in order to not leak resources. Even though we're calling this explicitly
190+
// further down, the method may exit before then.
191+
deferfunc() {
192+
// If we try close an already-closed writer, it'll send a subsequent request to the server which is invalid.
193+
_=closeOnce()
194+
}()
186195

187196
// Create message headers.
188197
msg:=&bytes.Buffer{}
@@ -250,7 +259,7 @@ func (s *SMTPHandler) dispatch(subject, htmlBody, plainBody, to string) Delivery
250259
returnfalse,xerrors.Errorf("write body buffer: %w",err)
251260
}
252261

253-
iferr=message.Close();err!=nil {
262+
iferr=closeOnce();err!=nil {
254263
returntrue,xerrors.Errorf("delivery failure: %w",err)
255264
}
256265

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp