Skip to content

fix: handle potential DB conflict due to concurrent upload requests in postFile #19005

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

Merged
merged 4 commits into from
Jul 30, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
add test to ensure that concurrent file uploads don't result in an error
Signed-off-by: Callum Styan <callumstyan@gmail.com>
  • Loading branch information
cstyan committed Jul 22, 2025
commit df947efe57e6bf66b36ff741d27979120a5190cf
29 changes: 29 additions & 0 deletions coderd/files_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
"bytes"
"context"
"net/http"
"sync"
"testing"

"github.com/google/uuid"
Expand Down Expand Up @@ -69,6 +70,34 @@
_, err = client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(data))
require.NoError(t, err)
})
t.Run("InsertConcurrent", func(t *testing.T) {
t.Parallel()
client := coderdtest.New(t, nil)
_ = coderdtest.CreateFirstUser(t, client)

ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitLong)
defer cancel()

var wg sync.WaitGroup
var end sync.WaitGroup
wg.Add(1)
end.Add(3)
for range 3 {

Check failure on line 85 in coderd/files_test.go

View workflow job for this annotation

GitHub Actions / lint

empty-lines: extra empty line at the end of a block (revive)
go func() {
wg.Wait()
data := make([]byte, 1024)
_, err := client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(data))
end.Done()
require.NoError(t, err)
}()

}
wg.Done()
end.Wait()

// _, err = client.Upload(ctx, codersdk.ContentTypeTar, bytes.NewReader(data))
// require.NoError(t, err)
})
}

func TestDownload(t *testing.T) {
Expand Down
Loading
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy