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

StateFlow causes stack overflow #1429

Open
QuasiStellar opened this issue Sep 5, 2024 · 1 comment
Open

StateFlow causes stack overflow #1429

QuasiStellar opened this issue Sep 5, 2024 · 1 comment

Comments

@QuasiStellar
Copy link

QuasiStellar commented Sep 5, 2024

I started with a working code that only operates pass-by-value serializable data classes. I converted one of the methods to return a StateFlow<T> instead of T:

// before (works)
override fun myZiplineServiceMethod(): MyType = _myValue
private var _myValue: MyType = someInitialValue

// now (doesn't work)
override fun myZiplineServiceMethod(): StateFlow<MyType> = _myValue
private val _myValue: MutableStateFlow<MyType> = MutableStateFlow(someInitialValue)

On the client-side the only difference is that I now call .value to get the value.

The zipline part compiles fine, but I get a crash at runtime, when I call .value:

Exception in thread "main" app.cash.zipline.QuickJsException: stack overflow
	at app.cash.zipline.JniCallChannel.call(Native Method)
	at app.cash.zipline.JniCallChannel.call(JniCallChannel.kt:25)
	at app.cash.zipline.Zipline$endpoint$1.call(Zipline.kt:65)
	at app.cash.zipline.internal.bridge.OutboundCallHandler.callInternal$zipline(OutboundCallHandler.kt:116)
	at app.cash.zipline.internal.bridge.OutboundCallHandler.call(OutboundCallHandler.kt:75)
	at app.cash.zipline.internal.bridge.StateFlowZiplineService$Companion$Adapter$GeneratedOutboundService.getValue(flows.kt:34)
	at app.cash.zipline.internal.bridge.StateFlowSerializer$toStateFlow$1.getValue(flows.kt:145)
        [here my client code calls .value on a StateFlow instance it received from zipline]

I used to get this error before when there were circular dependencies in my pass-by-value data classes which makes sense (also I would appreciate a more meaningful error message). But what happens here I have no idea.

I also tried using regular Flows before discovering from a random issue that StateFlows are supported too (please please work on the docs!) and with minimal changes got a QuickJs cannot read property "set_value_v1vabv_k$" of undefined and a SIGSEGV (!) on two separate occasions with even less info to work with. This is out of scope of this issue though.

@QuasiStellar
Copy link
Author

Update:
Apparently the problem only occurs when .value is taken outside the context of the single-threaded dispatcher.

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

1 participant