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

Data race via graphql #25868

Closed
holiman opened this issue Sep 26, 2022 · 4 comments
Closed

Data race via graphql #25868

holiman opened this issue Sep 26, 2022 · 4 comments
Assignees
Labels

Comments

@holiman
Copy link
Contributor

holiman commented Sep 26, 2022

Detected by travis cron-job (https://app.travis-ci.com/github/ethereum/go-ethereum/jobs/583768087)

==================
WARNING: DATA RACE
Write at 0x00c0006fe4a0 by goroutine 364:
  github.com/ethereum/go-ethereum/graphql.(*Transaction).Logs()
      /home/travis/gopath/src/github.com/ethereum/go-ethereum/graphql/graphql.go:466 +0x3b0
  runtime.call32()
      /home/travis/.gimme/versions/go1.19.1.linux.amd64/src/runtime/asm_amd64.s:725 +0x48
  reflect.Value.Call()
      /home/travis/.gimme/versions/go1.19.1.linux.amd64/src/reflect/value.go:368 +0xc7
  github.com/graph-gophers/graphql-go/internal/exec.execFieldSelection.func2()
      /home/travis/gopath/pkg/mod/github.com/graph-gophers/graphql-go@v1.3.0/internal/exec/exec.go:211 +0xa1b
  github.com/graph-gophers/graphql-go/internal/exec.execFieldSelection()
      /home/travis/gopath/pkg/mod/github.com/graph-gophers/graphql-go@v1.3.0/internal/exec/exec.go:231 +0x37d
  github.com/graph-gophers/graphql-go/internal/exec.(*Request).execSelections.func1()
      /home/travis/gopath/pkg/mod/github.com/graph-gophers/graphql-go@v1.3.0/internal/exec/exec.go:81 +0x2d4
  github.com/graph-gophers/graphql-go/internal/exec.(*Request).execSelections.func2()
      /home/travis/gopath/pkg/mod/github.com/graph-gophers/graphql-go@v1.3.0/internal/exec/exec.go:82 +0x47

Previous read at 0x00c0006fe4a0 by goroutine 365:
  github.com/ethereum/go-ethereum/rpc.(*BlockNumberOrHash).Hash()
      /home/travis/gopath/src/github.com/ethereum/go-ethereum/rpc/types.go:223 +0x144
  github.com/ethereum/go-ethereum/graphql.(*Transaction).Logs()
      /home/travis/gopath/src/github.com/ethereum/go-ethereum/graphql/graphql.go:460 +0xcb
  runtime.call32()
      /home/travis/.gimme/versions/go1.19.1.linux.amd64/src/runtime/asm_amd64.s:725 +0x48
  reflect.Value.Call()
      /home/travis/.gimme/versions/go1.19.1.linux.amd64/src/reflect/value.go:368 +0xc7
  github.com/graph-gophers/graphql-go/internal/exec.execFieldSelection.func2()
      /home/travis/gopath/pkg/mod/github.com/graph-gophers/graphql-go@v1.3.0/internal/exec/exec.go:211 +0xa1b
  github.com/graph-gophers/graphql-go/internal/exec.execFieldSelection()
      /home/travis/gopath/pkg/mod/github.com/graph-gophers/graphql-go@v1.3.0/internal/exec/exec.go:231 +0x37d
  github.com/graph-gophers/graphql-go/internal/exec.(*Request).execSelections.func1()
      /home/travis/gopath/pkg/mod/github.com/graph-gophers/graphql-go@v1.3.0/internal/exec/exec.go:81 +0x2d4
  github.com/graph-gophers/graphql-go/internal/exec.(*Request).execSelections.func2()
      /home/travis/gopath/pkg/mod/github.com/graph-gophers/graphql-go@v1.3.0/internal/exec/exec.go:82 +0x47
Goroutine 364 (running) created at:
func (t *Transaction) Logs(ctx context.Context) (*[]*Log, error) {
	if _, err := t.resolve(ctx); err != nil {
		return nil, err
	}
	if t.block == nil {
		return nil, nil
	}
	if _, ok := t.block.numberOrHash.Hash(); !ok {
		header, err := t.r.backend.HeaderByNumberOrHash(ctx, *t.block.numberOrHash)
		if err != nil {
			return nil, err
		}
		hash := header.Hash()
		t.block.numberOrHash.BlockHash = &hash             //  <--- THIS LINE
	}
	return t.getLogs(ctx)
}
func (bnh *BlockNumberOrHash) Hash() (common.Hash, bool) {
	if bnh.BlockHash != nil {                              //   <-- PREV READ
		return *bnh.BlockHash, true 
	}
	return common.Hash{}, false
}
@s1na
Copy link
Contributor

s1na commented Sep 26, 2022

This code keeps on giving...I'll look into it thanks for reporting.

@holiman
Copy link
Contributor Author

holiman commented Oct 13, 2022

t.block.numberOrHash.BlockHash = &hash 

Perhaps you can just change this to be set/read using atomic , via a setter and a getter?

@holiman
Copy link
Contributor Author

holiman commented Oct 13, 2022

Perhaps you can just change this to be set/read using atomic , via a setter and a getter?

Hm, the fields are public, so that's not a super-great change

@s1na
Copy link
Contributor

s1na commented Mar 30, 2023

Should be fixed as part of #26965.

@s1na s1na closed this as completed Mar 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants