gobgp icon indicating copy to clipboard operation
gobgp copied to clipboard

Clone OriginInfo in Path Clone

Open dawn-minion opened this issue 1 year ago • 2 comments

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.

dawn-minion avatar Oct 03 '23 22:10 dawn-minion

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.

dawn-minion avatar Oct 03 '23 22:10 dawn-minion

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

fujita avatar Oct 24 '23 13:10 fujita