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

[fix]: use weak reference to internal sinks when vending to clients #189

Merged
merged 2 commits into from
Feb 6, 2023

Conversation

jamieQ
Copy link
Contributor

@jamieQ jamieQ commented Feb 6, 2023

Description

previously we would allow a strong reference to the internal ReusableSink to be captured by the Sink types that are vended to clients. this meant that events sent into such 'external' sinks would still propagate through the event handling machinery a bit before realizing that the backing workflow node to which they were destined was no longer around. by using weak references we can prevent extending the life of the internal sinks (and underlying EventPipe) unnecessarily in such cases.

  • make ReusableSink captures weak when vending to the 'outside world'
  • update various access control values to facilitate testing this behavior

Checklist

  • Unit Tests
  • UI Tests
  • Snapshot Tests (iOS only)
  • I have made corresponding changes to the documentation

@@ -198,12 +198,11 @@ extension WorkflowNode.SubtreeManager {
func makeSink<Action>(of actionType: Action.Type) -> Sink<Action> where Action: WorkflowAction, WorkflowType == Action.WorkflowType {
let reusableSink = sinkStore.findOrCreate(actionType: Action.self)

let signpostRef = SignpostRef()
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

unrelated change, but figured we might as well not instantiate this here since it isn't necessarily going to be used (we could also further improve this with some additional changes).

@jamieQ jamieQ marked this pull request as ready for review February 6, 2023 22:00
@jamieQ jamieQ requested a review from a team as a code owner February 6, 2023 22:00
@@ -243,6 +243,26 @@ final class SubtreeManagerTests: XCTestCase {
XCTAssertEqual(manager.sideEffectLifetimes.count, 1)
XCTAssertEqual(manager.sideEffectLifetimes.keys.first, "key-2")
}

func test_eventPipes_notRetainedByExternalSinks() {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

confirmed this fails prior to the change introduced in this PR


XCTAssertNotNil(externalSink)
XCTAssertNil(weakEventPipe)
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice 👍

@jamieQ jamieQ merged commit 3fec0ee into main Feb 6, 2023
@jamieQ jamieQ deleted the jquadri/fix-internal-sink-retention branch February 6, 2023 22:16
jamieQ added a commit that referenced this pull request Feb 6, 2023
* main:
  [fix]: use weak reference to internal sinks when vending to clients (#189)
  [feat]: add primary associated types to more protocols (#188)
  [chore]: pre major version bump cleanup (#187)
  [chore]: bump minimum deployment & swift versions (#186)
  Abstract ViewEnvironment to shared framework (#185)
  Bump activesupport from 6.1.4.4 to 6.1.7.1 (#183)
  [feat]: add primary associated types to `Workflow` protocol (#181)
  [chore]: update swiftformat ifdef indent rule to no-indent (#182)
jamieQ added a commit that referenced this pull request Feb 25, 2023
…ow-workflow-conformance

* origin/main:
  Expose AnyScreen.wrappedScreen for inspection (#193)
  Improve introspection for SignalProducerWorkflow actions (#192)
  [release]: bump version to 2.2.0 & remove separate concurrency version (#191)
  [feat]: add runtime observation API (#168)
  [chore]: refactor some internal actions to use existential any (#190)
  [fix]: use weak reference to internal sinks when vending to clients (#189)
  [feat]: add primary associated types to more protocols (#188)
  [chore]: pre major version bump cleanup (#187)
  [chore]: bump minimum deployment & swift versions (#186)
  Abstract ViewEnvironment to shared framework (#185)
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