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

NS 8.2 Android crash when using http-Module inside worker #9819

Closed
3 tasks done
felixkrautschuk opened this issue Mar 9, 2022 · 4 comments
Closed
3 tasks done

NS 8.2 Android crash when using http-Module inside worker #9819

felixkrautschuk opened this issue Mar 9, 2022 · 4 comments
Labels

Comments

@felixkrautschuk
Copy link
Contributor

@felixkrautschuk felixkrautschuk commented Mar 9, 2022

Issue Description

When using the http-Module inside a worker script on Android, the app crashes wih the following stack:

System.err: com.tns.NativeScriptException: Cannot find object id for instance=com.tns.gen.org.nativescript.widgets.Async_CompleteCallback@530baa4
System.err: at com.tns.Runtime.callJSMethodImpl(Runtime.java:1181)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1175)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1153)
System.err: at com.tns.Runtime.callJSMethod(Runtime.java:1149)
System.err: at com.tns.gen.org.nativescript.widgets.Async_CompleteCallback.onComplete(Async_CompleteCallback.java:20)
System.err: at org.nativescript.widgets.Async$Http$HttpRequestTask.onPostExecute(Async.java:583)
System.err: at org.nativescript.widgets.Async$Http$1$1.run(Async.java:308)
System.err: at android.os.Handler.handleCallback(Handler.java:883)
System.err: at android.os.Handler.dispatchMessage(Handler.java:100)
System.err: at android.os.Looper.loop(Looper.java:214)
System.err: at android.app.ActivityThread.main(ActivityThread.java:7356)
System.err: at java.lang.reflect.Method.invoke(Native Method)
System.err: at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

On iOS, it seems to work as expected and on Android it was working with NS 8.1.

myworker.js
require("@nativescript/core/globals");

const http = require("@nativescript/core/http");

global.onmessage = function(msg) {
    if(msg.data.action === "test") {
        
      http.request({
        url: 'https://httpbin.org/get',
        method: 'GET'
      }).then(
        (response) => {
          const content = response.content
          const str = content.toString();
          console.log(str);

          console.log("worker sending message success...");
          global.postMessage({ success: true });
          console.log("worker has sent message");
        },
        e => {

        }
      )
    }
};


Reproduction

ns-worker-8.zip

Start the app and tap the Button on Android to start the worker script that is doing an http request, then the app will crash.

Relevant log output (if applicable)

System.err: com.tns.NativeScriptException: Cannot find object id for instance=com.tns.gen.org.nativescript.widgets.Async_CompleteCallback@530baa4
System.err:     at com.tns.Runtime.callJSMethodImpl(Runtime.java:1181)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1175)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1153)
System.err:     at com.tns.Runtime.callJSMethod(Runtime.java:1149)
System.err:     at com.tns.gen.org.nativescript.widgets.Async_CompleteCallback.onComplete(Async_CompleteCallback.java:20)
System.err:     at org.nativescript.widgets.Async$Http$HttpRequestTask.onPostExecute(Async.java:583)
System.err:     at org.nativescript.widgets.Async$Http$1$1.run(Async.java:308)
System.err:     at android.os.Handler.handleCallback(Handler.java:883)
System.err:     at android.os.Handler.dispatchMessage(Handler.java:100)
System.err:     at android.os.Looper.loop(Looper.java:214)
System.err:     at android.app.ActivityThread.main(ActivityThread.java:7356)
System.err:     at java.lang.reflect.Method.invoke(Native Method)
System.err:     at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
System.err:     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)

Environment

OS: macOS 12.2.1
CPU: (12) x64 Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
Shell: /bin/zsh
node: 14.18.1
npm: 6.14.15
nativescript: 8.1.5

# android
java: 11.0.11
ndk: Not Found
apis: Not Found
build_tools: Not Found
system_images: Not Found

# ios
xcode: 13.2.1/13C100
cocoapods: 1.11.2
python: 2.7.18
python3: 3.9.7
ruby: 2.7.4
platforms: 
  - DriverKit 21.2
  - iOS 15.2
  - macOS 12.1
  - tvOS 15.2
  - watchOS 8.3

Dependencies

"dependencies": {
  "@nativescript/core": "^8.2.0"
},
"devDependencies": {
  "@nativescript/android": "^8.2.1",
  "@nativescript/ios": "8.1.0",
  "@nativescript/webpack": "^5.0.6"
}

Please accept these terms

@felixkrautschuk felixkrautschuk added the bug-pending-triage label Mar 9, 2022
@edusperoni
Copy link
Contributor

@edusperoni edusperoni commented Mar 9, 2022

This crash was introduced in @nativescript/core@8.2.0-alpha.11, trying to find out what exactly caused it

@rigor789
Copy link
Member

@rigor789 rigor789 commented Mar 9, 2022

Looks like my change here: a31c823

We should be using Looper.myLooper() there. Woops!

@rigor789 rigor789 added bug and removed bug-pending-triage labels Mar 9, 2022
@rigor789
Copy link
Member

@rigor789 rigor789 commented Mar 9, 2022

@felixkrautschuk
Copy link
Contributor Author

@felixkrautschuk felixkrautschuk commented Mar 9, 2022

Thank you for the quick fix!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants