-
-
Notifications
You must be signed in to change notification settings - Fork 23
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
Server is Crashing on Android - React Native Expo App #26
Comments
Hi @jyotipixolo , I think you might be doing it wrong: with As a rapid test, can you try adding |
Hi @birdofpreyru, I tried stopping the server before starting it. To make things easier I took out all of my other code regarding the data and now I am just starting(After stopping) the server when I land on the screen and stopping when I exit.
But my server still crashes. And the crash happens at random moments, sometimes on server start and sometimes on server stop. Could this be a memory issue in android ? I don't always get the |
Agh... you know, getActiveServer() only returns a server, if any, when it is non- You should do at least as in the example app, where the hook just keeps server reference and stops it on unmount, i.e. (over-simplifying the example): useEffect(() => {
const server = new Server(..);
...
server.start(..).then(..);
return () => {
server.stop();
};
}, []); this way you don't leak references to the server instances you create, and ensure that every server is correctly shutdown when the hook unmounts. Note, even with such pattern, the example does it in the root app component, thus it is sure the hook never executed more than once a time in the app (in contrast to if you put it into some component, which can be mounted and unmounted). If you do it in some component, probably |
I also got the same issue. I have expo bare workflow project.
Nothing works. App is freezing randomly on different points. & without server code everything is working fine. I am attaching one simple project with server code with 2 screens in it, just starting & stopping the server in different ways. You can check it here : https://we.tl/t-dZ1nq3dmQk |
@ZakiPathan2010 please, re-read my previous comment. I see in your giant archive the same code fragment I commented about above, which potentially creates multiple server instances when the screen mounts/unmounts, because there is no syncrhonization between different screen instances, I guess; also it does not stop the server when screen is unmounted — I don't know what are you trying to do, but probably you'll do better if you just create a single server instance at the root of the app, and stop it when you are sure you don't need it. |
One more thing that needs to be considered is that my code is working absolutely fine in the IOS simulator and on a real device. But the server is crashing on Android. |
Well, on Android I use it in several app distributed via Google.Play, and installed on ~5k devices in total. All set up to report me errors and crashes via Sentry. So far I haven't seen the servers crashing there. Maybe I miss something; maybe your code works fine in ios and simulator because they implement the execution flow sync between js and native differently and it prevents potential issues with your code i pointed above. I'll be on the lookout for crashes on Android, but so far haven't seen them myself, but I also use it the way demoed in the example app. |
I tried clearing all the server instances before I start a new server. I made a function that returned an array of all the servers (in any state they are in). This always returned an empty array, only then I started a new server. But the freezing still exists. The server crash happens inside the "launch" function in the server.java file. Because any log after that is not seen. I also put the start server code inside a useEffect in my app.tsx too, with a plan that I start the server initially and keep it that way till I need it in my inner page. But I don't even get past my Login Screen and the server crashes and the app freezes. Is these a version of the plugin that is more suited for Android? |
That
You actually can see logs from Lighttpd in
I believe, earlier you told "Most of the times the server starts successfully the first time but causes issues when I go back from the screen and return to it", which to me indicates that you do some mistakes in handling those restarts.
No, there is no special version for Android, I rely on the same latest versions I released on NPM. |
I'm just trying to make it work now. So this is what I'm doing in my App.tsx. I tried to replicate the example code. I have taken out any restart code, or any references to the plugin on any other components. The server starts normally like always. My App.tsx has a stack of screens, the initial one being the Login Screen. While I'm still on the Login Screen the server crashes.
These are the Logs I feel would be relevant.
The above logs were formed without server.stop() being called. I noticed another log, way before the crash happened. Do you think there are any other packages in my code that might be clashing with yours? |
Well... are you sure there is nothing else in your app consuming too much memory, and thus triggering OS to garbage-collect / kill stuff?
☝️ This reads like, yeah, too much memory consumed, OS started to fight for resources.
☝️ These actually come from Lighttpd core. Should be looked up there, but the way they read... looks like the server attempted and completed a graceful shutdown, the same like when
☝️ And this comes from Java layer of this library, specifically from this point. As you see, there is a trivial logic behind it — if process exited with non-zero status — throw exception, say it crashed. So, if you wanna look into this further yourself, I guess the next thing is to look into Lighttpd sources, this file specifically, and try to figure out what can cause it to attempt a graceful shutdown and exit with -1 status. |
Hi @birdofpreyru , so here is what I’m trying to do in my sample project. This project has nothing else to make sure there is no memory leak from anywhere else. I started the server in app.tsx file (just like in the example code) which is the entry point of my app & I have two screens which navigates to each other without any server code. There is no reference to the server anywhere else in the code except the App.tsx. So what happens here, is that my server is starts as usual & when I navigate from 1st screen to 2nd screen & go back to 1st screen, after a few times the app freezes. In this process the app is not in background & I never closed it. In my main app too, after starting the server I would have to navigate to other screens as I did in my last example. I am attaching my project here so you can try it by yourself too. Sample Project |
So, I arrived to briefly look at your sample project now; and only now I realised it is an Expo project, which this library does not yet support officially. I tried to build by first removing artifacts from your builds you packed into the archive, and then doing Thus, I guess this issue will be on hold until I decide to support Expo. Before that, I can just re-iterate, for me the server works fine on Android with a regular RN project (see the example app in the repo); and stay on look-out for possible Android-specific issues. |
Tells who? Some kind of Artificial Idiocy?
These are two main reasons why this library is powered by Lighttpd — the same, actively maintained server across all platforms.
Nah... most probably it crashes because you do something wrong in your code; or there might be some bug in the library somewhere. |
Maybe I missed it, but you provided no evidence for that statement. Just an unsubstantiated conclusion. If you can trace the process or thread which starts lighttpd using
|
The plugin is working fine on IOS. But the server is getting crashed on Android after some time.
Package JSON
The way my app works is. I download a zip folder from a remote URL, I then extract it to a folder in RNFS /scorm-player/
Similarly, I download multiple modules to the same directory. Each module being anywhere between 20 MB - 160 MB in size. All of this happens before I start the local server. When I open the page where my Local Server is needed. I'm using this code to run the server.
Before I can update the SRC in the webview, I need to get some data (from a local SQLite database) about the module I want to play in the Webview, and create GET REQUEST PARAM string to pass in the Source URL. This works perfectly fine when I'm testing it on a iOS Simulator. But when I run the same thing on an Android Simulator. It works perfectly the first time. After that when I go back and open the page again, the app freezes completely, without throwing any exception. And then I see a console in Android Studio which says "Server crashed"
The text was updated successfully, but these errors were encountered: