Skip to content

Data race between StreamServer startup and atomic operations during initialization #1962

Description

@leovct

A data race occurs during cdk-erigon sequencer startup when two operations access the same memory location concurrently. The main goroutine attempts to write genesis data to the stream while a separate goroutine is still initializing the StreamServer.

==================
WARNING: DATA RACE
Write at 0x00c000f91480 by goroutine 111:
  github.com/0xPolygonHermez/zkevm-data-streamer/datastreamer.(*StreamServer).Start()
      github.com/0xPolygonHermez/zkevm-data-streamer@v0.2.8/datastreamer/streamserver.go:246 +0x3a4
  github.com/ledgerwatch/erigon/cmd/rpcdaemon/cli.StartDataStream()
      cmd/rpcdaemon/cli/config_zkevm.go:17 +0xa3
  github.com/ledgerwatch/erigon/eth.(*Ethereum).Init.func4()
      eth/backend.go:1402 +0x5d

Previous read at 0x00c000f91480 by main goroutine:
  github.com/0xPolygonHermez/zkevm-data-streamer/datastreamer.(*StreamServer).StartAtomicOp()
      github.com/0xPolygonHermez/zkevm-data-streamer@v0.2.8/datastreamer/streamserver.go:363 +0x2ed
  github.com/ledgerwatch/erigon/zk/datastream/server.(*ZkEVMDataStreamServer).WriteGenesisToStream()
      zk/datastream/server/datastream_populate.go:379 +0x168
  github.com/ledgerwatch/erigon/zk/stages.CatchupDatastream()
      zk/stages/stage_data_stream_catch_up.go:124 +0x658
  github.com/ledgerwatch/erigon/eth.(*Ethereum).PreStart()
      eth/backend.go:1427 +0xa4d
  github.com/ledgerwatch/erigon/turbo/node.New()
      turbo/node/node.go:139 +0x1e8
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  github.com/syndtr/goleveldb/leveldb.(*DB).checkAndCleanFiles()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db_util.go:52 +0x288
  github.com/syndtr/goleveldb/leveldb.openDB()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:136 +0x884
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x264
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:657 +0x18e
  fmt.(*ss).doScanf()
      fmt/scan.go:1230 +0x40e
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  github.com/syndtr/goleveldb/leveldb.(*DB).recoverJournal()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:482 +0xa6
  github.com/syndtr/goleveldb/leveldb.openDB()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:131 +0x86d
  github.com/syndtr/goleveldb/leveldb.Open()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:203 +0x364
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  github.com/syndtr/goleveldb/leveldb.(*session).recover.func1()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/session.go:134 +0xbd
  runtime.deferreturn()
      runtime/panic.go:477 +0x30
  github.com/syndtr/goleveldb/leveldb.Open()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:189 +0x124
  github.com/syndtr/goleveldb/leveldb.OpenFile()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:225 +0x84
  github.com/0xPolygonHermez/zkevm-data-streamer/datastreamer.NewBookmark()
      github.com/0xPolygonHermez/zkevm-data-streamer@v0.2.8/datastreamer/streambookmark.go:26 +0x106
  github.com/0xPolygonHermez/zkevm-data-streamer/datastreamer.NewServer()
      github.com/0xPolygonHermez/zkevm-data-streamer@v0.2.8/datastreamer/streamserver.go:217 +0x515
  github.com/ledgerwatch/erigon/zk/datastream/server.(*ZkEVMDataStreamServerFactory).CreateStreamServer()
      zk/datastream/server/data_stream_server.go:72 +0xa5
  github.com/ledgerwatch/erigon/eth.New()
      eth/backend.go:999 +0xa324
  github.com/ledgerwatch/erigon/turbo/node.New()
      turbo/node/node.go:131 +0x15e
  main.runErigon()
      cmd/cdk-erigon/main.go:71 +0x43b
  github.com/ledgerwatch/erigon/turbo/app.MakeApp_zkEvm.func1()
      turbo/app/make_app_zkevm.go:46 +0x2e4
  github.com/urfave/cli/v2.(*Command).Run()
      github.com/urfave/cli/v2@v2.27.2/command.go:276 +0x1458
  github.com/urfave/cli/v2.(*App).RunContext()
      github.com/urfave/cli/v2@v2.27.2/app.go:333 +0x12a6
  github.com/urfave/cli/v2.(*App).Run()
      github.com/urfave/cli/v2@v2.27.2/app.go:307 +0x115
  main.main()
      cmd/cdk-erigon/main.go:45 +0xda

Goroutine 111 (running) created at:
  github.com/ledgerwatch/erigon/eth.(*Ethereum).Init()
      eth/backend.go:1401 +0x2084
  github.com/ledgerwatch/erigon/turbo/node.New()
      turbo/node/node.go:135 +0x1bc
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  github.com/syndtr/goleveldb/leveldb.(*DB).checkAndCleanFiles()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db_util.go:52 +0x288
  github.com/syndtr/goleveldb/leveldb.openDB()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:136 +0x884
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x264
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:657 +0x18e
  fmt.(*ss).doScanf()
      fmt/scan.go:1230 +0x40e
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  github.com/syndtr/goleveldb/leveldb.(*DB).recoverJournal()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:482 +0xa6
  github.com/syndtr/goleveldb/leveldb.openDB()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:131 +0x86d
  github.com/syndtr/goleveldb/leveldb.Open()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:203 +0x364
  fmt.Fscanf()
      fmt/scan.go:143 +0xdc
  fmt.Sscanf()
      fmt/scan.go:114 +0x184
  github.com/syndtr/goleveldb/leveldb/storage.fsParseName()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:643 +0x1a
  github.com/syndtr/goleveldb/leveldb/storage.(*fileStorage).List()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/storage/file_storage.go:458 +0x3fd
  github.com/syndtr/goleveldb/leveldb.(*session).recover.func1()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/session.go:134 +0xbd
  runtime.deferreturn()
      runtime/panic.go:477 +0x30
  github.com/syndtr/goleveldb/leveldb.Open()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:189 +0x124
  github.com/syndtr/goleveldb/leveldb.OpenFile()
      github.com/syndtr/goleveldb@v1.0.1-0.20210819022825-2ae1ddf74ef7/leveldb/db.go:225 +0x84
  github.com/0xPolygonHermez/zkevm-data-streamer/datastreamer.NewBookmark()
      github.com/0xPolygonHermez/zkevm-data-streamer@v0.2.8/datastreamer/streambookmark.go:26 +0x106
  github.com/0xPolygonHermez/zkevm-data-streamer/datastreamer.NewServer()
      github.com/0xPolygonHermez/zkevm-data-streamer@v0.2.8/datastreamer/streamserver.go:217 +0x515
  github.com/ledgerwatch/erigon/zk/datastream/server.(*ZkEVMDataStreamServerFactory).CreateStreamServer()
      zk/datastream/server/data_stream_server.go:72 +0xa5
  github.com/ledgerwatch/erigon/eth.New()
      eth/backend.go:999 +0xa324
  github.com/ledgerwatch/erigon/turbo/node.New()
      turbo/node/node.go:131 +0x15e
  main.runErigon()
      cmd/cdk-erigon/main.go:71 +0x43b
  github.com/ledgerwatch/erigon/turbo/app.MakeApp_zkEvm.func1()
      turbo/app/make_app_zkevm.go:46 +0x2e4
  github.com/urfave/cli/v2.(*Command).Run()
      github.com/urfave/cli/v2@v2.27.2/command.go:276 +0x1458
  github.com/urfave/cli/v2.(*App).RunContext()
      github.com/urfave/cli/v2@v2.27.2/app.go:333 +0x12a6
  github.com/urfave/cli/v2.(*App).Run()
      github.com/urfave/cli/v2@v2.27.2/app.go:307 +0x115
  main.main()
      cmd/cdk-erigon/main.go:45 +0xda
==================

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions