fix: Take a read lock rather than an exclusive lock in getContextForTx - #26800
Open
SillyZir wants to merge 1 commit into
Open
fix: Take a read lock rather than an exclusive lock in getContextForTx#26800SillyZir wants to merge 1 commit into
SillyZir wants to merge 1 commit into
Conversation
getContextForTx acquired app.mu exclusively while reading only the state manager (which is independently synchronised by its own RWMutex) and app.sigverifyTx. app.mu documents itself as protecting name, version and appVersion; every other site in baseapp respects that scope, and this was the only writer outside the setup-time setters in options.go. Downgrading to a read lock removes a per-transaction exclusive acquisition from the execution path, so it no longer serialises against Name, Version, AppVersion and Info. Refs cosmos#24634
Contributor
|
PR author is not in the allowed authors list. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Ref: #24634 (partial — see Scope)
getContextForTxacquiredapp.muexclusively, but reads only:app.stateManager.GetState(mode)— the state manager is independentlysynchronised by its own
sync.RWMutex(baseapp/state/manager.go)app.sigverifyTxapp.GetConsensusParams(ctx), which does not touchapp.muapp.mudocuments itself as protectingname,versionandappVersion.Every other use in
baseapprespects that scope — the readers (Name,Version,AppVersion,Info) takeRLock, and the only writers are thesetup-time setters in
options.go.getContextForTxwas the sole exception.Since it is called per transaction from
runTx, that exclusive acquisitionserialised transaction execution against those readers for no reason.
Scope
This does not address the
stateManager.stateMutcontention #24634 alsoimplies.
CreateQueryContextWithCheckHeaderdoes not takeapp.muon its hotpath, so query latency specifically is unaffected except via
Name()on the"not ready" branch. Filed as a partial improvement rather than a fix — happy to
close it if you would rather see the issue addressed as a whole.
Testing
go test -race ./baseapp/...passes (baseapp 185s, plus blockexec, oe,txnrunner). No regression test: the change narrows a lock scope without
altering behaviour, so no input fails before and passes after.