The app I'm building, when I compile it for distribution packing it with electron-builder, every now and then, dies, showing a blank screen and a disconnected devtools:
Any ideas what's going on or how to start figuring out what's happening here?
Listen for the uncaughtException event and log any error that you get. This will give you insight into what is happening. Then perform any cleanup if necessary and relaunch the app if desired. This allows your app to "recover" from crashes if it is intended to be long-running.
//handle crashes and kill events
process.on('uncaughtException', function(err) {
//log the message and stack trace
fs.writeFileSync('crash.log', err + "\n" + err.stack);
//do any cleanup like shutting down servers, etc
//relaunch the app (if you want)
app.relaunch({args: []});
app.exit(0);
});
You can also listen to the SIGTERM event to see if your application is being killed off, and also gracefully shutdown servers, restart, etc.
process.on('SIGTERM', function() {
fs.writeFileSync('shutdown.log', "Received SIGTERM signal");
//do any cleanup like shutting down servers, etc
//relaunch the app (if you want)
app.relaunch({args: []});
app.exit(0);
});
This can be caused by several different serious faults in the renderer process (out of memory, for example). To fix it, you really have to get your hands on the error.
See https://www.electronjs.org/docs/tutorial/application-debugging#v8-crashes for more details. Specifically, I would recommend settings the ELECTRON_ENABLE_LOGGING environment variable to true before launching the electron process, this should result in the error showing up in the console from which you launch the main process (NOT the chrome devtools console).
Related
I'm trying to have my electron app do a bunch of cleanup when the app is quit (terminate a few processes, delete some temp files, etc). I am triggering the cleanUp function with the before-quit event. If my computer is running fast, these cleanup operations complete before the app is quit, but if the computer is running slow, the cleanUp function sometimes only executes partially.
Is there a way that I can prevent the app from fully quitting before my cleanUp function has been fully executed?
app.on('before-quit', async () => {
try {
await cleanUp();
} catch (err) {
console.error(err);
}
});
As you can read in the before-quit docs, you can use event.preventDefault() inside the before-quit event handler to prevent the app from terminating.
Your cleanup code can then run unimpeded. At the end of the cleanup, close the app programmatically.
To make sure that before-quit will not block app termination at that time, you probably want to keep track of the current state of the app. You may want to allow the app to terminate inside before-quit if the cleanup code has completed. That means: execute event.preventDefault() only if the cleanup has not been completed yet.
It's probably wise to inform the user about the state of the app: display "shutting down" or something similar, so that it is clear that the app is no longer functional.
I'm using Swift 3 with a WebRTC pod called "PodRTC".
If I open a connection, close and open another works perfect. But if I have an open connection for some unfortunate reason I try to created new par connection, the app blockeding. Or the opposite, if you try to close a connection that is not open the app also hangs.
These hanging happen randomly, but always when I call a "close" method. Here is an example:
private func prepareNewPeer() {
if let peer = self.peer, peer.responds(to: #selector(RTCPeerConnection.close)) {
do {
peer.close()
}
}
self.chatChannel = nil
self.peer = nil
....
The application simply hangs, but neither does it generate errors. Apparently, it does not loop because processing is low. It looks like some bug inside the library.
This happens in the .close () method call. I tried to protect the method in every way, but to no avail.
OBS: It is worth mentioning that sometimes it is not just the app that hangs but the entire operating system. I can not play anything else until I compile a new version with Xcode or reboot the phone or wait a few minutes.
To interrupt the app using Xcode's "Pause program execution" button and see what's happening on the various threads:
The line in my code that stopped, was ".close()" and previous comment.
I'm building an electron app that must reload the render process window if a crash happens.
Currently I can restart the app from the main process
app.relaunch();
app.quit();
But I cannot detect the window crashing.
I tried using the
win.on('unresponsive', () => { ... } );
But the event is not getting generated when I crash the process.
To crash the process I tried:
invoking the process.crash()
using all the available memory.
Both ways successfully crash the process but again, I cannot find a way to detect it.
I tried also using, from the render process, the window.onerror(...) and sending via IPC to the main process a message when the crash is detected, but this seems not to work as well.
You should be looking for the 'crashed' event in webContents. Check https://electronjs.org/docs/api/web-contents#event-crashed
For example put something like this in main process:
win.webContents.on('crashed', (e) => {
app.relaunch();
app.quit()
});
maybe look into "pm2-windows-service" which can install your app as windows service and watch if it crashes, to restart it
https://www.npmjs.com/package/pm2-windows-service
also electron has app.setLoginItemSettings({ openAtLogin: true }); but that does not guard for crash, only provide automatic app start at windows login
I have an IONIC2 app, which needs to wake up every morning at 8 AM for 20 minutes to send user reminders based on the user's geolocation.
I am using this plugin (which uses IOS significant changes API to monitor changes in user's location)
https://github.com/mauron85/cordova-plugin-background-geolocation
The problem:
The app doesn't get killed when I close the app and the background geolocation works for me fine for some time. I have tested upto an hour. But when I wake up next morning, I find the app was killed by IOS.
I know there is another plugin to keep the app running in the background https://github.com/katzer/cordova-plugin-background-mode, but I have read tons of complaints from people that it will cause your app to be rejected by the AppStore (In fact, the plugin has a disclaimer to the same effect too).
For waking up the app tomorrow, I simply set a setTimeout
setTimeout(function(){
console.log('waking up');
self.helper.scheduleLocalNotification('Hello World', 'Good Morning', 10, "");
self.ionViewDidEnter();
}, wakeupinMilliSeconds);
Here is my geolocation code:
setupBackGroundGeolocation(){
let config = {
desiredAccuracy: 100,
stationaryRadius: 50,
distanceFilter: 100,
interval: 5000,
pauseLocationUpdates: false,
debug: false, // enable this hear sounds for background-geolocation life-cycle.
stopOnTerminate: false, // enable this to clear background location settings when the app terminates
};
BackgroundGeolocation.configure((location) => {
console.log('[js] BackgroundGeolocation callback: ' + location.latitude + ',' + location.longitude);
this.currentLocation.lat = location.latitude;
this.currentLocation.lng = location.longitude;
Promise.all([
//I do some calculations here.
]).then(d => {
// IMPORTANT: You must execute the finish method here to inform the native plugin that you're finished,
// and the background-task may be completed. You must do this regardless if your HTTP request is successful or not.
// IF YOU DON'T, ios will CRASH YOUR APP for spending too much time in the background.
BackgroundGeolocation.finish(); // FOR IOS ONLY
});
}, (error) => {
console.log('BackgroundGeolocation error');
}, config);
// Turn ON the background-geolocation system. The user will be tracked whenever they suspend the app.
BackgroundGeolocation.start();
}
I don't use this plugin but had same symptons. I couldn't figure out what was wrong: no error messages, no clues but app kept closing after a few hours.
I guess there was something messed up after installing and uninstalling so many cordova plugins. Now the app is much more stable. I removed and added platform. That seemed to do the job.
I've been reading about ionic2 and performance. Among so many reasons, a possibility about low performance and crash is related not to unsubscribe from observables. Read about async pipe and .unsubscribe observables when component is destroyed ngOnDestroy
Another problem i found was a very basic mistake developing in angular. I loaded everything in the app module so this required lot of memory to load the entire app at once. I guess with slow terminals that can affect more. Anyway, basic angular concepts as .module files should be understood.
When I add the following code to my react-native app, memory usage soars from 40MB to 400MB in ten minutes (and keeps going) as soon as I take the app offline.
root.child(".info/connected").on("value", (snap) => {
if (snap.val() === true) {
this.online = true;
info("Going online");
if (this.user) { /* counter already loaded */
debug("posting offline transactions");
}
} else {
this.online = false;
info("Going offline");
}
});
The app itself is entirely quiescent and the .on() listener is not getting triggered. When I bring the phone back online memory usage stabilizes but does not decrease.
I have no idea how to debug this. I cannot run the app under the Chrome debugger because the phone has to be online to connect to the debugger. I cannot use the iOS simulator because to bring that offline you have to bring the whole computer offline and then you get the error: WebSocket connection failed
The only way I have to debug is to view console.log messages in xcode and my app has lots of them, but nothing is happening in the app itself.
I need to monitor offline/online state in order to work around the fact that Firebase transactions consume a large amount of memory when the app is used offline.