JaneaSystems / nodejs-mobile

Full-fledged Node.js on Android and iOS
https://code.janeasystems.com/nodejs-mobile
Other
2.55k stars 183 forks source link

PThread Exception running Vuepress server #117

Open jamesstidard opened 5 years ago

jamesstidard commented 5 years ago

I am looking to see if I am able to run a local vuepress server on iOS. However on starting the server, a few moments in, a pthread exception is raised. I tried skimming through the stack trace but wasn't able to find anything that would help me figure out what's going wrong.

I was wondering if I could get some help resolving the issue. Or some pointers.

I've forked the example iOS project and replaced it with a bear bones vuepress server. That can be found here:

https://github.com/jamesstidard/nodejs-mobile-samples/tree/vuepress/ios/native-xcode-node-folder

Thanks.

jaimecbernardo commented 5 years ago

Hi @jamesstidard ,

I've cloned the repo and tried running the sample, and left it running for a couple of minutes, and didn't get any PThread Exceptions on an iPhone 6S running iOS 11.4

I'm not familiar with the plugin, so what would the expected behavior be, to make sure I'm running it right? Would you be able to describe some reproduction steps, so that these could be followed?

jamesstidard commented 5 years ago

Hi @jaimecbernardo ,

appreciate the help.

Vuepress takes a directory of markdown files and renders it as a website. So this call to vuepress is starting a server which should convert the hello world markdown file I've created in a temporary directory. This is the hello world of vuepress.

Once it is running the application should be able to render to home page by opening a web view and browsing to localhost:8080. However, I did not include a webview and the permissions to browse insecure content in this fork because I was trying to keep it as close to the original as possible. I could add them if it would help.

However, I don't believe it gets to the stage of actually serving the site before I experience a crash.

Here is the expected console output of vuepress - which I run using my laptops node instalation:

desktop

And here is the output I get running the same thing with the iOS node (as you can see it raises an exception).

ios

I hope this clears it up a bit. You did mention that you ran it on a real device - I'm running mine on a simulator. I'll try mine on a real device as well.

Thanks for your time.

P.S. Here's that output from xcode if it's helpful:


 WAIT  Extracting site metadata...
[?25l
Compiling

● Client █████████████████████████ compiling (0%)  

[?25l
Compiling

● Client █████████████████████████ building modules (10%) 2/2 modules 0 active

[?25l
Compiling

● Client █████████████████████████ building modules (10%) 2/3 modules 1 active

...ode-node-folder.app/nodejs-project/node_modules/vuepress/lib/app/clientEntry.
js

/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/native-xcode-node-folder[16657]: ../src/node_util.cc:167:void node::util::PromiseResolve(const FunctionCallbackInfo<v8::Value> &): Assertion `promise->IsPromise()' failed.
 1: node::Abort() [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
 2: node::(anonymous namespace)::DomainEnter(node::Environment*, v8::Local<v8::Object>) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
 3: node::util::PromiseReject(v8::FunctionCallbackInfo<v8::Value> const&) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
 4: v8::FunctionCallbackData::FunctionInvoked(void*, bool, void**, unsigned short, void*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
 5: Js::JavascriptExternalFunction::StdCallExternalFunctionThunk(Js::RecyclableObject*, Js::CallInfo, ...) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
 6: amd64_CallFunction [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
 7: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
 8: Js::InterpreterStackFrame::ProcessThunk(void*, void*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
 9: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
10: Js::InterpreterStackFrame::InterpreterThunk(Js::RecyclableObject*, Js::CallInfo, ...) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
11: amd64_CallFunction [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
12: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
13: Js::InterpreterStackFrame::ProcessThunk(void*, void*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
14: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
15: Js::InterpreterStackFrame::InterpreterThunk(Js::RecyclableObject*, Js::CallInfo, ...) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
16: amd64_CallFunction [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
17: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
18: Js::InterpreterStackFrame::ProcessThunk(void*, void*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
19: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
20: Js::InterpreterStackFrame::InterpreterThunk(Js::RecyclableObject*, Js::CallInfo, ...) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
21: amd64_CallFunction [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
22: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
23: Js::InterpreterStackFrame::ProcessThunk(void*, void*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
24: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
25: Js::InterpreterStackFrame::InterpreterThunk(Js::RecyclableObject*, Js::CallInfo, ...) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
26: amd64_CallFunction [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
27: Js::InterpreterStackFrame::ProcessUnprofiled() [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
28: Js::InterpreterStackFrame::ProcessThunk(void*, void*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
29: Js::InterpreterStackFrame::InterpreterHelper(Js::ScriptFunction*, Js::ArgumentReader, void*, void*, Js::InterpreterStackFrame::AsmJsReturnStruct*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
30: Js::InterpreterStackFrame::InterpreterThunk(Js::RecyclableObject*, Js::CallInfo, ...) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
31: amd64_CallFunction [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
32: Js::JavascriptFunction::CallRootFunction(Js::Arguments, Js::ScriptContext*, bool) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
33: JsCallFunction [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
34: v8::Function::Call(v8::Local<v8::Context>, v8::Local<v8::Value>, int, v8::Local<v8::Value>*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
35: node::InternalCallbackScope::Close() [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
36: node::InternalMakeCallback(node::Environment*, v8::Local<v8::Object>, v8::Local<v8::Function>, int, v8::Local<v8::Value>*, node::async_context) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
37: node::(anonymous namespace)::After(uv_fs_s*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
38: uv__work_done [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
39: uv__async_io [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
40: uv__io_poll [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
41: uv_run [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
42: node::Start(v8::Isolate*, void*, int, char const* const*, int, char const* const*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
43: node::Start(uv_loop_s*, int, char const* const*, int, char const* const*) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
44: node::Start(int, char**) [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/Frameworks/NodeMobile.framework/NodeMobile]
45: +[NodeRunner startEngineWithArguments:] [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/native-xcode-node-folder]
46: -[AppDelegate startNode] [/Users/james/Library/Developer/CoreSimulator/Devices/1FEDF3AA-8B7E-4684-9BA5-EC80C4103732/data/Containers/Bundle/Application/F019CE90-419C-46B5-A364-1814E80FA64C/native-xcode-node-folder.app/native-xcode-node-folder]
47: __NSThread__start__ [/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/CoreSimulator/Profiles/Runtimes/iOS.simruntime/Contents/Resources/RuntimeRoot/System/Library/Frameworks/Foundation.framework/Foundation]
48: _pthread_body [/usr/lib/system/libsystem_pthread.dylib]
49: _pthread_start [/usr/lib/system/libsystem_pthread.dylib]
50: thread_start [/usr/lib/system/libsystem_pthread.dylib]
jamesstidard commented 5 years ago

I did try running this on an actual device (though my device is in the public beta at the moment: 12.0), and I think I seen what you had seen @jaimecbernardo . The app launched without crashing. Though the server didn't start up after I left it for a few minutes.

I tested this with a WebKit view pointed at localhost:8080. I've push that to my fork as well: https://github.com/jamesstidard/nodejs-mobile-samples/commit/5ce0f73beef81c7dcfa6ccc0df73f13a2a6b86e1

So I assume the same crash is happening on the device but less logs are shown when run on a device?

jaimecbernardo commented 5 years ago

Hi @jamesstidard ,

I've tried the new version and I've noticed a few points:

In terms of general points, it's possible vuepress is doing some operations that would be unavailable on iOS. Here's the example of some operations vuepress might be making that would not be available:

When running on a simulator, the application can do some of the operations that would be forbidden in an actual device. It is possible that, in the device, the vuepress code runs into a failing operation that it is checking against but it's successful while running in the simulator, to have an issue later on with a different operation.

The error being observed is because there seems to be a promise rejection being called without an actual promise object being passed in, which is being verified by an assert in the native code.

In the case of the specific application, a more usual workflow would be to have the files pre-built and included in the application's assets, instead of being built in the fly. If the idea is to get the files from some remote location and compiling them on the spot, Apple App Store guidelines would forbid it.

I hope this is helpful. Please let us know if you are able to further identify what the plugin might be doing to cause this.

jamesstidard commented 5 years ago

@jaimecbernardo Yeah looks like I forgot some changes, sorry for the dodgy push.

OK, that makes sense. Thanks.

Is there a way I can maybe get a more intelligible stack trace out it to see what line of the vuepress library it is failing on? That seems to be my problem at the moment is that it's a little blackboxy.

jaimecbernardo commented 5 years ago

@jamesstidard ,

The promise rejection should be able to show up as an Exception in the node runtime, which would be more helpful. There is a possible bug here, so we'll do some further investigation to understand why this isn't happening in this case.

jamesstidard commented 5 years ago

Hi again. I recently took another shot at this but am still not able to decipher the stack trace to figure out what's causing it.

I've updated my fork/branch to fir the missing WebKit framework so should work out of the box for people now (bar dropping in the node-mobile framework and npm installing).

Thanks for your time.