Skip to content

blob/azureblob: fix panic in writer.Close when the upload fails - #3803

Merged
vangent merged 2 commits into
google:masterfrom
therayquaza:fix-azureblob-writer-close-panic
Oct 21, 2026
Merged

vangent merged 2 commits into
google:masterfrom
therayquaza:fix-azureblob-writer-close-panic

Conversation

@therayquaza

@therayquaza therayquaza commented Oct 19, 2026 •

Copy link
Copy Markdown
Contributor

Summary

blob/azureblob's writer.Close() panics with a nil-pointer dereference when the upload fails after the body has been accepted. The error should be returned, not crash the process.

Cause: since 0633e97 (#3741), Close defers a closure that reads w.pr, but the upload goroutine clears w.pr (w.pr = nil) when UploadStream fails. By the time the deferred w.pr.Close() runs, the field is nil -> panic.

Fix

  • Double checking w.pr nilness in closure

Test

TestWriterCloseCommitError uses a local server that drains the body, then returns 409 BlobAlreadyExists, so the error surfaces from Close. It panics without this fix and passes with it (verified deterministic, -race and lint clean).

Signed-off-by: Mateo Lelong <mateo.lelong@datadoghq.com>
@google-cla

google-cla Bot commented Oct 19, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@therayquaza therayquaza changed the title fix: azure blob commit error panic blob/azureblob: fix panic in writer.Close when the upload fails Oct 19, 2026
@codecov

codecov Bot commented Oct 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 80.52%. Comparing base (5a8f86d) to head (547e166).

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #3803      +/-   ##
==========================================
+ Coverage   80.02%   80.52%   +0.50%     
==========================================
  Files         104      104              
  Lines       12318    12317       -1     
==========================================
+ Hits         9857     9918      +61     
+ Misses       2460     2398      -62     
  Partials        1        1              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

if w.err != nil {
if closePipeOnError {
w.pr.CloseWithError(w.err)
w.pr = nil

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Can we restore this?

Comment thread blob/azureblob/azureblob.go Outdated
func (w *writer) Close() (err error) {
if !w.upload {
if w.pr != nil {
if pr := w.pr; pr != nil {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

And then change the closure to not use a capture variable but rather check w.pr for nilness before trying to close?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

f69808b unsure why we are unsetting the w.pr when failing but I reverted and added another condition in the closure to avoid panics

Signed-off-by: Mateo Lelong <mateo.lelong@datadoghq.com>
@vangent
vangent merged commit 4abc4f5 into google:master Oct 21, 2026
13 checks passed
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.

2 participants