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

fix: patch data race #869

Merged
merged 8 commits into from
Nov 17, 2022
11 changes: 8 additions & 3 deletions rpc/core/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package core
import (
"encoding/base64"
"fmt"
"sync"
"time"

cfg "github.com/tendermint/tendermint/config"
Expand Down Expand Up @@ -35,12 +36,16 @@ const (

var (
// set by Node
mut = &sync.Mutex{}
env *Environment
)

// SetEnvironment sets up the given Environment.
// It will race if multiple Node call SetEnvironment.
// SetEnvironment sets up the given Environment. The env global var that this
// function modifies is protected by a sync.Once, so multiple calls within the
// same process will not be effective.
func SetEnvironment(e *Environment) {
mut.Lock()
defer mut.Unlock()
env = e
}

Expand Down Expand Up @@ -69,7 +74,7 @@ type peers interface {
Peers() p2p.IPeerSet
}

//----------------------------------------------
// ----------------------------------------------
// Environment contains objects and interfaces used by the RPC. It is expected
// to be setup once during startup.
type Environment struct {
Expand Down