How to find out why an app quits after starting?

Hello all.

I have this happen all the time, basically everytime I update my console app, or web app that runs on a Pi… The app will start, then quit by itself. The error logs show nothing, the Linux Sys log(s) show only the startup and the log entries I have coded into the app - but nothing with regard to why the app would spontaneously quit!

Tonite, I updated the SQLite database, and added Xojoversionstring to the app so it would write it to the database on start, and then could be read by a web app page.

Can anyone tell me some clues to solve why this is happening and what to do about it?

In some cases, it has been Xojo version - I have better luck with 2017R3 than any of the 2018 versions. But again, it is different from app to app. ie some apps compiled in 2018Rx are fine, some are not. Some must be done in 2017R3. Sometimes it is helpful to shut down the Pi, sometimes it does not matter (just stop the app, upload new and restart the app). Very very strange!

Anyway, this is an enormous problem since it take hours to get it figured out, and there is never a ryhm or reason as to why it finally works! Not good for something that should be production ready!

If it’s a standalone web app, check to make sure the previous version has been terminated. If a web app cannot listen on the port you requested, it will immediately quit.

Hi Greg,
I always kill the apps before uploading a replacement.
In the scenario you outined, does the framework write to any system log or provide any indication whatsoever of the cause of the shutdown?

In my case, the standalone web app is not the problem, but other console apps are! Is there any way to find out why they are starting then shutting down?

Tim

Use the UnhandledException Event of the Application object to log the Error Stack.

Also check yo have all the dependencies installed

I Ivan.
The apps eventually run - no depedency issues at all. When I make a minor change is when things come apart! I forget which version of Xojo to use, since some do not work! This is what prompted last nights change by adding the Xojoversionstring.

I’ll recheck the unhandled exception, but I am pretty sure that this is part of the logging code…

Tim

I change the code in the Unhandled Exception from writing to my own files to writing to the system.

System.Log( System.LogLevelCritical, "Unhandled Exception " + error.Message + "  " + error.Type )
Return False

After recompiling, there is still nothing in any of the system logs that show anything about the app. It starts, runs for a second or two, then stops.

BTW compiling with Windows, Xojo 2017R3.
Any other ideas???
Thanks,
Tim

I would try running a remote debugging session to the PI (is that available?) and see what happens in the debugger. If that won’t work, then add in system.log steps EVERYWHERE you can, particularly in the close and cancel close events. In fact, you may want to raise an exception in one of those events. Then in the unhandled exception event you can get the stack trace and see what is calling close.

One more comment - I remember having things like this happen and it would vary from Xojo version to Xojo version, but this was back when the web platform was really new. In the end, I believe the real problem with my app quitting all the time was that things were going out of scope when they shouldn’t have been. So make sure that whatever you need to keep the app up and going stays in scope.

Shure, that is a nightmare. I need to have 3 different xojo installed.

Do you replace the folder or dete the old app first? Try to delete the entire folder. Then , copy all the contents of the compiled app.

Also, do you set permissions for the app and files it might use?

Also remember to edit the permissions of all the files you copy to the Pi.

This is not a web app that I am currently having trouble with - it is a console app.
There are no missing decencies either - since the last version worked perfectly, just added a few lines of code, which BTW, I removed to see if that was the issue!

An old backup copy of the app was just tested, it runs perfectly and stays running.

I’m going to try compiling on a Linux machine to see if that has any effect, to move on I hope so, but if that cures it, what a PIA!

I’ll try adding a raised event to make sure that the code in the unhandled exceptions gets run. Not sure if the remote debugger really works or not on Windows. I do not like using the Linux machine, it is cumbersome for me - 'cause I don’t use it!

Tim

Deleting folders did not help…

Do you start your console application manually after the raspberry pi boots up or do you have it auto start via Cron or something?

In normal operation it starts automatically.
In these tests I cannot tell if it is stated auto then quits or not. But I do start manually double clicking on the file. Other versions work that way - including a backup which I just resorted to…

Tim

Are you daemonizing the application? if not, can you write to stdout at various points in the startup of your code to see where it fails?

I am daemonizing, and also am logging all the way up to the loop. All of those checkins are perfect. It just quits…
Tim

So it makes it all the way to the loop? Then dies?

Does it always quit as soon as it hits the loop? Or does it run a while? Any idea how many loop iterations complete before it dies?

Seems to quit when it gets to the loop. Hard to tell, runs for maybe a second or two in total.

Console apps have no main thread. They run trough the “Run” event and then exit. You should have a while loop something like:

While Not App.Close

App.DoEvents(10)

App.MyMainLoopMethod

Wend

Return 0

Now you should create the App.MyMainLoopMethod as that’s where your main loop code should go (keeps executing that, with yielding 10ms to the system after it.

Add a property App.Close As Boolean = False
Whe you set App.Close =True the app should automaticly quit.

Read more here:
https://documentation.xojo.com/api/language/consoleapplication.html

Remember that dependencies change acording the Xojo version used to compile. Try compiling with an older one.

Does it run any longer if you don’t daemonize the application?

You haven’t said much about what you are doing leading up to the main loop or what you are doing inside the main loop. Are you initializing the GPIO system or opening TCP Sockets in your application?

Try to get your application to run as a standard console application and then after everything checks out, daemonize it. In my experience, daemonizing is the final thing you want to do after getting the application stable.