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

Kotlin/JS: Browser locks up while ResponseAdapter and BufferedSourceJsonReader processes data #4590

Closed
farmerbb opened this issue Dec 18, 2022 · 6 comments

Comments

@farmerbb
Copy link

farmerbb commented Dec 18, 2022

Version

3.7.2

Summary

We are experiencing browser lockups while using Apollo Kotlin via Kotlin/JS.
When executing a query, the actual network call appears to succeed, but when the response is processed, it locks the browser up, usually during the selectName() function of BufferedSourceJsonReader.

Lockups are occurring on both Chrome 108.0.5359.124 and Firefox 102.6.0esr on Ubuntu 22.10.
Apollo Kotlin version is 3.7.2 using Kotlin 1.7.21.

I am able to reproduce the lockups across multiple schemas, including the rocketreserver example schema hosted at https://apollo-fullstack-tutorial.herokuapp.com/graphql.
Example project + logs are included below. Thanks!

Steps to reproduce the behavior

  • Clone the example repository:
git clone https://github.com/Angel-Studios/apollo-js-lockup-example
  • Start the web app:
./gradlew jsBrowserRun
  • Expected behavior is that the app will print the list of launch sites in the document body.
  • Actual behavior: The app locks the web browser up, saturating a CPU core.

Logs

Script terminated by timeout at: BufferedSourceJsonReader.kt:753:11
BufferedSourceJsonReader.prototype.selectName_mhpeer$@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:5529:12
LaunchListQuery_ResponseAdapter$Mission.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-js-lockup-example.js:387:22
ObjectAdapter.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:553:43
NullableAdapter.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:329:36
LaunchListQuery_ResponseAdapter$Launch.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-js-lockup-example.js:351:91
ObjectAdapter.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:553:43
NullableAdapter.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:329:36
ListAdapter.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:296:44
LaunchListQuery_ResponseAdapter$Launches.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-js-lockup-example.js:306:97
ObjectAdapter.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:553:43
LaunchListQuery_ResponseAdapter$Data.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-js-lockup-example.js:267:81
ObjectAdapter.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:553:43
NullableAdapter.prototype.fromJson_p35aje$@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:329:36
ResponseParser.prototype.parse_cql2zi$@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:4220:50
parseJsonResponse@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-api-js-legacy.js:2826:41
HttpNetworkTransport.prototype.singleResponse_0@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-runtime-js-legacy.js:3430:14
Coroutine$HttpNetworkTransport$execute$lambda.prototype.doResume@webpack-internal:///./kotlin-dce-dev/apollo-kotlin-apollo-runtime-js-legacy.js:3388:152
CoroutineImpl.prototype.resumeWith_tl1gpc$@webpack-internal:///./kotlin-dce-dev/kotlin.js:40213:35
DispatchedTask.prototype.run@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:29162:24
MessageQueue.prototype.process@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32545:17
WindowMessageQueue$schedule$lambda/<@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32499:31
promise callback*WindowMessageQueue.prototype.schedule@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32504:27
MessageQueue.prototype.enqueue_771g0p$@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32532:12
WindowDispatcher.prototype.dispatch_5bn72i$@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32453:18
dispatch@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:29204:20
CancellableContinuationImpl.prototype.dispatchResume_0@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:1534:13
CancellableContinuationImpl.prototype.resumeImpl_0@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:1559:16
CancellableContinuationImpl.prototype.resumeWith_tl1gpc$@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:1481:10
readChunk$lambda$lambda/<@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16803:28
promise callback*readChunk$lambda/<@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16815:29
suspendCancellableCoroutine$lambda_0/<@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16691:20
Coroutine$readChunk.prototype.doResume@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16837:105
readChunk@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16866:23
Coroutine$channelFromStream$lambda.prototype.doResume@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16731:29
CoroutineImpl.prototype.resumeWith_tl1gpc$@webpack-internal:///./kotlin-dce-dev/kotlin.js:40213:35
DispatchedTask.prototype.run@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:29162:24
MessageQueue.prototype.process@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32545:17
WindowMessageQueue$schedule$lambda/<@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32499:31
promise callback*WindowMessageQueue.prototype.schedule@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32504:27
MessageQueue.prototype.enqueue_771g0p$@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32532:12
WindowDispatcher.prototype.dispatch_5bn72i$@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32453:18
dispatch@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:29204:20
CancellableContinuationImpl.prototype.dispatchResume_0@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:1534:13
CancellableContinuationImpl.prototype.resumeImpl_0@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:1559:16
CancellableContinuationImpl.prototype.resumeWith_tl1gpc$@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:1481:10
readChunk$lambda$lambda/<@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16803:28
promise callback*readChunk$lambda/<@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16815:29
suspendCancellableCoroutine$lambda_0/<@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16691:20
Coroutine$readChunk.prototype.doResume@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16837:105
readChunk@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16866:23
Coroutine$channelFromStream$lambda.prototype.doResume@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16731:29
channelFromStream$lambda/<@webpack-internal:///./kotlin-dce-dev/ktor-ktor-client-core-js-legacy.js:16793:25
Coroutine$launchChannel$lambda.prototype.doResume@webpack-internal:///./kotlin-dce-dev/ktor-ktor-io-js-legacy.js:5527:34
CoroutineImpl.prototype.resumeWith_tl1gpc$@webpack-internal:///./kotlin-dce-dev/kotlin.js:40213:35
DispatchedTask.prototype.run@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:29162:24
MessageQueue.prototype.process@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32545:17
WindowMessageQueue$schedule$lambda/<@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32499:31
promise callback*WindowMessageQueue.prototype.schedule@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32504:27
MessageQueue.prototype.enqueue_771g0p$@webpack-internal:///./kotlin-dce-dev/kotlinx-coroutines-core.js:32532:12
@farmerbb
Copy link
Author

@ToxicBakery keeping you in the loop on this

@BoD
Copy link
Contributor

BoD commented Dec 19, 2022

Hi 👋

Thanks a lot for opening this, and with a reproducer 🙏.

I noticed that the issue disappears when using the IR compiler backend:

kotlin {
-    js {
+    js(IR) {
    binaries.executable()
    //...

I must admit I am not sure why it hangs with the default (LEGACY) one, but given that it will be deprecated with Kotlin 1.8, it is probably time for us to stop supporting it.

@martinbonnin
Copy link
Contributor

martinbonnin commented Dec 19, 2022

it will be deprecated with Kotlin 1.8

IIRC, js(LEGACY) is even removed, I had to remove it in our own 1.8 PR

@farmerbb
Copy link
Author

Thanks! I'm seeing it work on my end as well using the IR compiler backend. Appreciate your help!

@martinbonnin
Copy link
Contributor

IIRC, js(LEGACY) is even removed, I had to remove it in our own 1.8 PR

For the record, I didn't remember correctly, LEGACY is still there in 1.8.0-RC and outputs this warning:

==========
This project currently uses the Kotlin/JS Legacy compiler backend, which has been deprecated and will be removed in a future release.

Please migrate the project to the new IR-based compiler (https://kotl.in/jsir).
==========

I'd still vote to stop supporting LEGACY.

@BoD
Copy link
Contributor

BoD commented Dec 20, 2022

Starting with v3.7.3, the Legacy version is no longer published, and trying to configure it will fail with a message saying that only IR is supported. Closing this one for now.

@BoD BoD closed this as completed Dec 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants