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

Clone OriginInfo in Path Clone #2715

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

dawn-minion
Copy link
Contributor

OriginInfo assigned to Path objects is a pointer to the originating peer's info, which is populated by the FSM goroutine handling the peer's connection. This value is typically protected by the FSM lock, but in the event a path watch is running, it gets converted to a protobuf object in toPathAPI in a separate goroutine. This method reads from this same structure without any data synchronisation, leading to a data race.

To ensure this cannot happen, this commit adds a line to clone the field before it is passed to the event watcher, ensuring the data race cannot occur.

This issue was found when the project was built using Golang's data race detector.

OriginInfo assigned to Path objects is a pointer to the originating
peer's info, which is populated by the FSM goroutine handling the peer's
connection. This value is typically protected by the FSM lock, but in
the event a path watch is running, it gets converted to a protobuf
object in toPathAPI in a separate goroutine. This method reads from this
same structure without any data synchronisation, leading to a data
race.

To ensure this cannot happen, this commit adds a line to clone the field
before it is passed to the event watcher, ensuring the data race cannot
occur.
@dawn-minion
Copy link
Contributor Author

I wasn't quite sure what you folks would prefer here to resolve this, and this seemed the least invasive as it's a simple copy. Let me know if you want it changed of course.

@fujita
Copy link
Member

fujita commented Oct 24, 2023

Clone() is used everywhere and this increases memory footprint. Can we copy peer's info only when Clone() is used for watcher?

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

Successfully merging this pull request may close these issues.

2 participants