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

UploadOrUpdateFile() not goroutine safe #27

Open
Hawaii66 opened this issue Mar 16, 2024 · 1 comment
Open

UploadOrUpdateFile() not goroutine safe #27

Hawaii66 opened this issue Mar 16, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@Hawaii66
Copy link

Hawaii66 commented Mar 16, 2024

Bug report

Describe the bug

Using one supabase client with multiple goroutines and multiple calls to UploadOrUpdateFile() might cause a race condition to MIMEHeader.Set()

To Reproduce

`
func ProcessUploadImage(){
c, d := storageClient.UploadFile("images", dbImage.externalPath, file, storage_go.FileOptions{
ContentType: &dbImage.format,
})
}

supabase := supabase.CreateClient(SUPABASE_URL, SUPABASE_ANON_KEY)
for i := 0; i < status.Upload; i++ {
go ProcessUploadImage(i, doneChannel, deleteChannel, supabaseStorage)
}
`

Expected behavior

Either documentation to explain the problem or a change to include a mutex

Stdout with -race flag

`

WARNING: DATA RACE
Write at 0x00c000038d20 by goroutine 35:
runtime.mapassign_faststr()
C:/Program Files/Go/src/runtime/map_faststr.go:203 +0x0
net/textproto.MIMEHeader.Set()
C:/Program Files/Go/src/net/textproto/header.go:22 +0x413
net/http.Header.Set()
C:/Program Files/Go/src/net/http/header.go:40 +0x375
github.com/supabase-community/storage-go.(*Client).UploadOrUpdateFile()
C:/Users/hawai/go/pkg/mod/github.com/supabase-community/storage-go@v0.7.0/storage.go:38 +0x309
github.com/supabase-community/storage-go.(*Client).UploadFile()
C:/Users/hawai/go/pkg/mod/github.com/supabase-community/storage-go@v0.7.0/storage.go:76 +0x39e
main.UploadImage()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:203 +0x2f2
main.ProcessUploadImage()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:227 +0xc4
main.main.func6()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:433 +0x5d

Previous write at 0x00c000038d20 by goroutine 36:
runtime.mapassign_faststr()
C:/Program Files/Go/src/runtime/map_faststr.go:203 +0x0
net/textproto.MIMEHeader.Set()
C:/Program Files/Go/src/net/textproto/header.go:22 +0x413
net/http.Header.Set()
C:/Program Files/Go/src/net/http/header.go:40 +0x375
github.com/supabase-community/storage-go.(*Client).UploadOrUpdateFile()
C:/Users/hawai/go/pkg/mod/github.com/supabase-community/storage-go@v0.7.0/storage.go:38 +0x309
github.com/supabase-community/storage-go.(*Client).UploadFile()
C:/Users/hawai/go/pkg/mod/github.com/supabase-community/storage-go@v0.7.0/storage.go:76 +0x39e
main.UploadImage()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:203 +0x2f2
main.ProcessUploadImage()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:227 +0xc4
main.main.func6()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:433 +0x5d

Goroutine 35 (running) created at:
main.main()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:433 +0x40a

Goroutine 36 (running) created at:
main.main()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:433 +0x40a

==================
WARNING: DATA RACE
Write at 0x00c00016c200 by goroutine 35:
net/textproto.MIMEHeader.Set()
C:/Program Files/Go/src/net/textproto/header.go:22 +0x424
net/http.Header.Set()
C:/Program Files/Go/src/net/http/header.go:40 +0x375
github.com/supabase-community/storage-go.(*Client).UploadOrUpdateFile()
C:/Users/hawai/go/pkg/mod/github.com/supabase-community/storage-go@v0.7.0/storage.go:38 +0x309
github.com/supabase-community/storage-go.(*Client).UploadFile()
C:/Users/hawai/go/pkg/mod/github.com/supabase-community/storage-go@v0.7.0/storage.go:76 +0x39e
main.UploadImage()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:203 +0x2f2
main.ProcessUploadImage()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:227 +0xc4
main.main.func6()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:433 +0x5d

Previous write at 0x00c00016c200 by goroutine 36:
net/textproto.MIMEHeader.Set()
C:/Program Files/Go/src/net/textproto/header.go:22 +0x424
net/http.Header.Set()
C:/Program Files/Go/src/net/http/header.go:40 +0x375
github.com/supabase-community/storage-go.(*Client).UploadOrUpdateFile()
C:/Users/hawai/go/pkg/mod/github.com/supabase-community/storage-go@v0.7.0/storage.go:38 +0x309
github.com/supabase-community/storage-go.(*Client).UploadFile()
C:/Users/hawai/go/pkg/mod/github.com/supabase-community/storage-go@v0.7.0/storage.go:76 +0x39e
main.UploadImage()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:203 +0x2f2
main.ProcessUploadImage()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:227 +0xc4
main.main.func6()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:433 +0x5d

Goroutine 35 (running) created at:
main.main()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:433 +0x40a

Goroutine 36 (running) created at:
main.main()
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:433 +0x40a

fatal error: concurrent map writes

goroutine 37 [running]:
net/textproto.MIMEHeader.Set(...)
C:/Program Files/Go/src/net/textproto/header.go:22
net/http.Header.Set(...)
C:/Program Files/Go/src/net/http/header.go:40
github.com/supabase-community/storage-go.(*Client).UploadOrUpdateFile(0xc000172000, {0x1406238be, 0x6}, {0xc000582640, 0x36}, {0x1406ce080?, 0xc00008c000}, 0x0, {0xc00076fd70, 0x1, ...})
C:/Users/hawai/go/pkg/mod/github.com/supabase-community/storage-go@v0.7.0/storage.go:38 +0x414
github.com/supabase-community/storage-go.(*Client).UploadFile(...)
C:/Users/hawai/go/pkg/mod/github.com/supabase-community/storage-go@v0.7.0/storage.go:76
main.UploadImage({{0xc000702400, 0x40}, {0xc000582640, 0x36}, 0x63a69, {0xc000624196, 0xa}}, 0x0?)
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:203 +0x39f
main.ProcessUploadImage(0x0?, 0x0?, 0x0?, 0x0?)
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:227 +0xc5
created by main.main in goroutine 1
C:/Users/hawai/OneDrive/Skrivbord/Projects/ULTRA/Veckans300/go/main.go:433 +0x40b
`

@Hawaii66 Hawaii66 added the bug Something isn't working label Mar 16, 2024
@jerichosiahaya
Copy link
Contributor

Have you tried using go mutex?

https://go.dev/tour/concurrency/9

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants