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 on cursor #27

Open
YaroShkvorets opened this issue Apr 22, 2023 · 2 comments
Open

Data race on cursor #27

YaroShkvorets opened this issue Apr 22, 2023 · 2 comments

Comments

@YaroShkvorets
Copy link
Contributor

Looks like there is a potential data race scenario that could result in the sink writing incorrect cursor to the database.
Hard to recreate but race detecter sees it:

go run -race . inject -e mainnet.eth.streamingfast.io:443 "badger3://$(pwd)/badger_data.db" ../../examples/wasm-query-service/substreams.yaml
==================
WARNING: DATA RACE
Read at 0x00c003bcf600 by goroutine 412:
  github.com/streamingfast/substreams-sink-kv/db.cursorToBytes()
      /Users/shkvo/github/Pinax/StreamingFast/substreams-sink-kv/db/cursor.go:38 +0xbe
  github.com/streamingfast/substreams-sink-kv/db.(*DB).WriteCursor()
      /Users/shkvo/github/Pinax/StreamingFast/substreams-sink-kv/db/cursor.go:30 +0x64
  github.com/streamingfast/substreams-sink-kv/sinker.(*KVSinker).Stop()
      /Users/shkvo/github/Pinax/StreamingFast/substreams-sink-kv/sinker/sinker.go:117 +0x11d
  github.com/streamingfast/substreams-sink-kv/sinker.New.func1()
      /Users/shkvo/github/Pinax/StreamingFast/substreams-sink-kv/sinker/sinker.go:74 +0xa0
  github.com/streamingfast/shutter.(*Shutter).Shutdown()
      /Users/shkvo/go/pkg/mod/github.com/streamingfast/[email protected]/shutter.go:111 +0x174
  main.injectRunE.func1()
      /Users/shkvo/github/Pinax/StreamingFast/substreams-sink-kv/cmd/substreams-sink-kv/inject.go:142 +0x87
  github.com/streamingfast/shutter.(*Shutter).Shutdown()
      /Users/shkvo/go/pkg/mod/github.com/streamingfast/[email protected]/shutter.go:111 +0x174
  main.injectRunE.func5()
      /Users/shkvo/github/Pinax/StreamingFast/substreams-sink-kv/cmd/substreams-sink-kv/inject.go:180 +0x3d

Previous write at 0x00c003bcf600 by goroutine 88:
  github.com/streamingfast/substreams-sink.NewCursor()
      /Users/shkvo/go/pkg/mod/github.com/streamingfast/[email protected]/types.go:18 +0x1065
  github.com/streamingfast/substreams-sink.(*Sinker).doRequest()
      /Users/shkvo/go/pkg/mod/github.com/streamingfast/[email protected]/sinker.go:268 +0xff8
  github.com/streamingfast/substreams-sink.(*Sinker).run()
      /Users/shkvo/go/pkg/mod/github.com/streamingfast/[email protected]/sinker.go:164 +0xbc4
  github.com/streamingfast/substreams-sink.(*Sinker).Start()
      /Users/shkvo/go/pkg/mod/github.com/streamingfast/[email protected]/sinker.go:114 +0x266
  github.com/streamingfast/substreams-sink-kv/sinker.(*KVSinker).Run()
      /Users/shkvo/github/Pinax/StreamingFast/substreams-sink-kv/sinker/sinker.go:147 +0x6aa
  github.com/streamingfast/substreams-sink-kv/sinker.(*KVSinker).Start()
      /Users/shkvo/github/Pinax/StreamingFast/substreams-sink-kv/sinker/sinker.go:109 +0x5c4
  main.injectRunE.func2()
      /Users/shkvo/github/Pinax/StreamingFast/substreams-sink-kv/cmd/substreams-sink-kv/inject.go:146 +0x64
@maoueh
Copy link
Contributor

maoueh commented May 18, 2023

This seems to happen at shutdown of the whole stack, so I'll take a closer look.

The code around shutdown has been heavily refactored in v2 bump, I'll run again with race detection to see if it stills report the problem.

@maoueh
Copy link
Contributor

maoueh commented May 18, 2023

Ok it actually finds other also now. I'll try to take time next week to dig deeper.

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

No branches or pull requests

2 participants