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

Detect host-side node, widget, and view leaks #2254

Merged
merged 1 commit into from
Aug 27, 2024

Conversation

JakeWharton
Copy link
Collaborator

@JakeWharton JakeWharton commented Aug 21, 2024

Refs #575.


  • CHANGELOG.md's "Unreleased" section has been updated, if applicable.

@JakeWharton JakeWharton force-pushed the jw.leak-integration.2024-08-13 branch 4 times, most recently from cc24296 to 4b6edaa Compare August 22, 2024 20:50
"Redwood-internal widget protocol node when $cause"
}

// Detaching frees the node's reference to the widget, so this must be done last.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Nice comment!

.addModifiers(OVERRIDE)
.returns(STRING)
// This explicit string builder usage allows sharing of strings in dex.
// See https://jakewharton.com/the-economics-of-generated-code/#string-duplication.
Copy link
Collaborator

Choose a reason for hiding this comment

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

👨🏻‍🍳👌🏻

timeSource = TimeSource.Monotonic,
leakThreshold = 10.seconds,
listener = object : LeakListener() {
override fun onReferenceLeaked(
Copy link
Collaborator

Choose a reason for hiding this comment

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

I’d like to somehow wire things together so that this is just another event to listen to in EventListener

Copy link
Collaborator

Choose a reason for hiding this comment

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

(And we’d need to hoist the policy up to the TreehouseApp.Factory or something)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I originally had this design, but it meant that the ownership of creating the LeakDetector and running its coroutine are deep inside the code.

I think maybe the listener of whether something leaks should be supplied when you watch something. This allows the decision of whether the leak detector is real or not to be very far away from the "watch this and notify me" call.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I don't think this makes sense. The EventListener is scoped to a code load. We can use that for reporting guest-side leaks, but it's not a good fit for host-side. Host-side leaks need to monitor things like the Zipline instance whose lifetime exceeds that of the EventListener. Since we null the real listener on cancel (to avoid a leak), we'd have nowhere to report actual leaks. I think for now I'm going to leave the whole LeakDetector exposed through the factory.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Once we get guest-side leaks, they'll come through the EventListener.

@JakeWharton JakeWharton force-pushed the jw.leak-integration.2024-08-13 branch 2 times, most recently from fd2ec00 to c47f8dc Compare August 26, 2024 20:54
@JakeWharton JakeWharton marked this pull request as ready for review August 26, 2024 20:59
@JakeWharton
Copy link
Collaborator Author

This is ready but it's 5pm and I'm not starting a rebase. Tomorrow problem.

@JakeWharton JakeWharton force-pushed the jw.leak-integration.2024-08-13 branch 2 times, most recently from 830fef6 to f5e2860 Compare August 27, 2024 16:30
*/
public suspend fun checkLeaks()
public suspend fun awaitClose()
Copy link
Collaborator

Choose a reason for hiding this comment

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

👍🏻


leakDetector.checkLeaks()
assertThat(listener.events).isEmpty()
// No refs? No GC.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Yay negative testing

@JakeWharton JakeWharton force-pushed the jw.leak-integration.2024-08-13 branch from f5e2860 to cc09030 Compare August 27, 2024 16:44
@JakeWharton JakeWharton enabled auto-merge (squash) August 27, 2024 17:45
@JakeWharton JakeWharton merged commit e64f319 into trunk Aug 27, 2024
11 checks passed
@JakeWharton JakeWharton deleted the jw.leak-integration.2024-08-13 branch August 27, 2024 17:57
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