Skip to content

[WIP] Refactor ChiStatus internals to make concurrent access safe#1117

Closed
zcross wants to merge 1 commit intoAltinity:0.21.0from
zcross:zcross/concurrency/status
Closed

[WIP] Refactor ChiStatus internals to make concurrent access safe#1117
zcross wants to merge 1 commit intoAltinity:0.21.0from
zcross:zcross/concurrency/status

Conversation

@zcross
Copy link
Copy Markdown
Contributor

@zcross zcross commented Feb 28, 2023

Background: #1109
Sibling PR(s):

This PR adds sync.RWMutex based synchronization over the mutable state of ChiStatus. It should be relatively straightforward.

The most eyebrow raising bits are probably in the sequenced lock acquisition in MergeActions and CopyFrom creating some risk of deadlocking (to be discussed, I'm sure). The only other potentially "hairy" concern is some of the generated code I've found for DeepCopy helpers on all types. I think I need to read surrounding code more deeply to understand if there are any indirect deep copies happening (i.e., sidestepping synchronization).

Note: I'll squash all commits from feedback pre-merge.

Important items to consider before making a Pull Request

Please check items PR complies to:

  • All commits in the PR are squashed. More info
  • The PR is made into dedicated next-release branch, not into master branch1. More info
  • The PR is signed. More info

@zcross zcross changed the base branch from master to 0.21.0 February 28, 2023 17:40
@zcross
Copy link
Copy Markdown
Contributor Author

zcross commented Feb 28, 2023

Will add a golang concurrent test (for -race coverage) today, basically matching the style of that in my other PR.

@zcross
Copy link
Copy Markdown
Contributor Author

zcross commented Feb 28, 2023

FYI @sunsingerus : I plan on making my way through each of registry/status/announcer, but thought having a separate PR for each would be valuable in keeping discussion focused (and not missing details due to the size of one big PR)

@zcross zcross marked this pull request as draft February 28, 2023 19:10
@zcross
Copy link
Copy Markdown
Contributor Author

zcross commented Feb 28, 2023

Update: I'm marking this as a draft for now, will promote back to PR when I have landed the concurrency test coverage and continue plumbing through synchronization into all getter/setter accesses to the status (I'm currently working my way through the medium sized surface area exposed by the combination of EnsureStatus()... calls and the slightly messier to track direct ChiStatus struct field accesses.

I'm pondering a few routes forward:

  • Exposing a general purpose readStatus(func(s *ChiStatus){}) and updateStatus(func (s *ChiStatus){}) call that transparently performs necessary locking – something error prone but less error prone than throwing locks on existing field level accesses
  • Chase down all existing field-level accesses of ChiStatus struct fields (exported for serialization purposes) and add explicit synchronization in all the places I find – something error prone and probably inviting future regressions
  • Introducing a new type that wraps ChiStatus and guards all read/write/merging/etc, pushing down ChiStatus to only serialization/deserialization to/from JSON/YAML – probably the least error prone technique since I'll be able to create a little more friction against direct field level accesses that bypass synchronization

@zcross
Copy link
Copy Markdown
Contributor Author

zcross commented Mar 1, 2023

Yeah, this is going to be more of a lift than I first thought, so I'm going to close this PR for now and reopen it when the branch is further along. Sorry for the premature draft :)

@zcross zcross closed this Mar 1, 2023
@zcross zcross changed the title Refactor ChiStatus internals to make concurrent access safe [WIP] Refactor ChiStatus internals to make concurrent access safe Mar 1, 2023
@zcross
Copy link
Copy Markdown
Contributor Author

zcross commented Mar 2, 2023

Whoops, can't reopen this because I rebased/squash after taking a second approach. Will open a new PR. Sorry!

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.

1 participant