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

I get a data race at internalLoadPredictSizePerValue #26

Closed
egor-ryashin opened this issue Aug 7, 2023 · 10 comments
Closed

I get a data race at internalLoadPredictSizePerValue #26

egor-ryashin opened this issue Aug 7, 2023 · 10 comments
Labels
bug Something isn't working good first issue Good for newcomers

Comments

@egor-ryashin
Copy link

egor-ryashin commented Aug 7, 2023

image

when I call this v, err := jsonvalue.Unmarshal(serialized)

@Andrew-M-C
Copy link
Owner

Andrew-M-C commented Aug 7, 2023

Is there any source code to reproduce this bug? And what is your OS env? I think it may indeed be a problem in 32-bit machines.

@Andrew-M-C Andrew-M-C added bug Something isn't working good first issue Good for newcomers labels Aug 7, 2023
@Andrew-M-C
Copy link
Owner

If you are using 32-bit system, you can degraded to v1.3.3. I will fix it ASAP

@egor-ryashin
Copy link
Author

64-bit root:xnu-8796.121.3~7/RELEASE_ARM64_T6000 arm64
I think go test -race with the mentioned v, err := jsonvalue.Unmarshal(serialized) should catch it. I see the warning during CI tests.

Andrew-M-C added a commit that referenced this issue Aug 7, 2023
@Andrew-M-C
Copy link
Owner

ARM64 MacBook? I borrowed one (Apple M1 Pro) and ran go test -v -race, not errors shown.

I reviewed the codes by myself, there IS a race problem for 32-bit system. I should fix it and release a new one soon.

But for arm64? I think the direct access to an uint64 variable should be goroutine safe. What do you think? Am I wrong?

@Andrew-M-C
Copy link
Owner

no matter how, I will release a new tag to solve this protencial race problem. If you are in hurry, please downgrade to v1.3.3.

Andrew-M-C added a commit that referenced this issue Aug 10, 2023
@Andrew-M-C
Copy link
Owner

Or you may try my latest feature/v1.3.5 branch

@egor-ryashin
Copy link
Author

egor-ryashin commented Aug 10, 2023

But for arm64? I think the direct access to an uint64 variable should be goroutine safe. What do you think? Am I wrong?

I speculate, it can be atomic but it's not guaranteed. Depends on how a particular compiler and compiler configuration decided to produce a target instruction.

@Andrew-M-C
Copy link
Owner

Andrew-M-C commented Aug 10, 2023

Please try feature/v1.3.5, I had removed the "predit" codes. They are not as effecient as I thought.

Andrew-M-C added a commit that referenced this issue Aug 11, 2023
Andrew-M-C added a commit that referenced this issue Aug 11, 2023
Andrew-M-C added a commit that referenced this issue Aug 11, 2023
@egor-ryashin
Copy link
Author

Yes, that solved it, thanks. I use this code to reproduce (with go run -test main.go):

package main

import (
	"fmt"
	"github.com/Andrew-M-C/go.jsonvalue"
	"sync"
)

func main() {
	limit := 10
	var wg sync.WaitGroup
	wg.Add(5)
	for i := 0; i < 5; i++ {
		go func(j int) {
			for j := 0; j < 100; j++ {
				v, err := jsonvalue.Unmarshal([]byte(fmt.Sprintf(`
	{
	   "class":"CONSTANT",
	   "type":"VALUE_CONSTANT",
	   "alias":"",
	   "value":{
		  "type":{
			 "id":"INTEGER",
			 "type_info":null
		  },
		  "is_null":false,
		  "value":%d
	   }
	}
`, limit)))
				if err != nil {
					panic(err)
				}
				v.Append(nil)

			}
			wg.Done()
		}(i)
	}
	wg.Wait()
}

for example:

go get "github.com/Andrew-M-C/go.jsonvalue@e60bf16"
go: downloading github.com/Andrew-M-C/go.jsonvalue v1.3.5-0.20230811042225-e60bf16ecdf7
go: upgraded github.com/Andrew-M-C/go.jsonvalue v1.3.4 => v1.3.5-0.20230811042225-e60bf16ecdf7
macbook:rill-developer$ go run -race maintest/testrace/main.go
macbook:rill-developer$ go run -race maintest/testrace/main.go
macbook:rill-developer$ go get "github.com/Andrew-M-C/go.jsonvalue@v1.3.4"
go: downgraded github.com/Andrew-M-C/go.jsonvalue v1.3.5-0.20230811042225-e60bf16ecdf7 => v1.3.4
macbook:rill-developer$ go run -race maintest/testrace/main.go
==================
WARNING: DATA RACE
Write at 0x000102f3e398 by goroutine 9:

@Andrew-M-C
Copy link
Owner

v1.3.5 released and officially fixed.

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

No branches or pull requests

2 participants