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

SuspendCallbacks can leak #828

Closed
swankjesse opened this issue Dec 23, 2022 · 6 comments
Closed

SuspendCallbacks can leak #828

swankjesse opened this issue Dec 23, 2022 · 6 comments
Milestone

Comments

@swankjesse
Copy link
Contributor

I’ve got a Redwood application that creates and cancels flows, and in some situations I’ve got SuspendCallback objects that never get called back, and never get canceled. I suspect it’s a book-keeping issue with ZiplineScope, possibly exacerbated by our flows.

I’m able to create this leak by creating and closing services. The leaked callback is tracked in Endpoint.inboundServices; here’s a sample.

zipline/host-1029 -> {InboundService@56720} SuspendCallback/Call(receiver=zipline/js-865, function=suspend fun emit(T): kotlin.Unit, args=[HostConfiguration(darkMode=false)])
@swankjesse
Copy link
Contributor Author

I traced through and learned what’s happening:

  1. Outbound side makes a suspending call to a target service T that passes a service K by-reference, like FlowZiplineService.collect()
  2. The call is encoded, which puts K in the outbound side’s inboundServices map
  3. That coroutine suspends in OutboundCallHandler.callSuspending()
  4. The target service T is closed by some other coroutine
  5. The target service cannot decode the call because T is closed, and therefore doesn’t discover that K needs to be closed

I’m gonna fix #826 first, which will prevent that untimely suspension.

One other gotcha here: the outbound side does receive the ZiplineApiMismatchException crash because its coroutine is already canceled by the time that arrives. This is a problem because we don’t get a signal that a leak could have happened.

@damianw
Copy link

damianw commented Jan 12, 2023

I found a similar issue with using Flows generally - it seems that both SuspendCallback and CancelCallbacks are leaked. I created a sample project based on the trivial example here: https://github.com/damianw/zipline-leaky-flow

Running the sample prints some leaks. Using the debugger, we can see that these were SuspendCallback and CancelCallback. Is this ultimately the same problem as described in this issue, or should I file a new issue?

@swankjesse
Copy link
Contributor Author

I expect it’s likely the same issue. Could I talk you into contributing a test case?

@damianw
Copy link

damianw commented Jan 12, 2023

Sure, will take a look. 👍

@damianw
Copy link

damianw commented Jan 12, 2023

Added a test in #850, though I'm not sure that this is really the same issue anymore. Or maybe it is, and nothing is really leaking. Let me know what you think.

@swankjesse swankjesse added this to the 1.0 milestone May 4, 2023
@swankjesse
Copy link
Contributor Author

Confirmed fixed by the ZiplineScope features.

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

No branches or pull requests

2 participants