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

[Bug]: Race condition on app.checkTxState #18844

Closed
1 task done
nivasan1 opened this issue Dec 20, 2023 · 3 comments · Fixed by #18846
Closed
1 task done

[Bug]: Race condition on app.checkTxState #18844

nivasan1 opened this issue Dec 20, 2023 · 3 comments · Fixed by #18846
Labels

Comments

@nivasan1
Copy link
Contributor

nivasan1 commented Dec 20, 2023

Is there an existing issue for this?

  • I have searched the existing issues

What happened?

The Issue

Proposed Solution

  • Add a CurrentHeader field to the baseApp that is wrapped by a mutex to avoid the need for unsynchronized accesses to the app.checkTxState.
  • Technically, baseApp ABCI methods are not thead-safe, but all cometBFT ABCI methods are executed synchronously (localAppConn). A different solution could be to make the app-states thread-safe, but this is a much larger lift IMO

Cosmos SDK Version

v0.50

How to reproduce?

No response

@alexanderbez
Copy link
Contributor

Great write up, thanks @nivasan1.

So while the AppManager/runtime stuff is being worked on, this should still be addressed for current and future v0.50.x Eden users.

I believe your proposal would work. Another proposal I would consider is making the private state type thread-safe, i.e. add a mutex to it and define a getter for the context.

func (s *state) getContext() sdk.Context {
  s.mtx.RLock()
  defer s.mtx.RUnlock()

  return s.ctx
}

And ensure all readers call getContext() rather than using the field directly.

cc @tac0turtle @julienrbrt

@nivasan1
Copy link
Contributor Author

@alexanderbez How would you make runTx / extended usage of the state.ctx synchronized with accesses to getCtx? You would need some form of reference counting, I'd imagine? Maybe I'm misunderstanding tho?

@alexanderbez
Copy link
Contributor

@alexanderbez How would you make runTx / extended usage of the state.ctx synchronized with accesses to getCtx? You would need some form of reference counting, I'd imagine? Maybe I'm misunderstanding tho?

So you don't need to make Context synchronized, after all, it's a non-mutative Context. What you do is you simply make the assumption that the underlying storage primative, in this case, RootStore, is synchronized.

@tac0turtle tac0turtle moved this from 👀 To Do to 📚 In review in Cosmos-SDK Dec 21, 2023
@github-project-automation github-project-automation bot moved this from 📚 In review to 🥳 Done in Cosmos-SDK Dec 21, 2023
@tac0turtle tac0turtle removed this from Cosmos-SDK Feb 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants