Dealing with web app restarts... again

Latest build this morning with 2025 R3. Earlier today with 2024 R3 (I previously had better luck with this version but it started restarting regularly after an hour or so). This is deployed on Xojo Cloud

I’ve been dealing with this pretty consistently over the past several weeks with making a small change, deploying, and hoping the change I made was the fix the app needed. My last stable app was somewhere around April last year, which was my last app version using 2024 R3

Here are some of the things I’ve added/changed going back to Novemberish:

  • Added Try/Catch blocks around anything db related
  • Switched from using * in my SELECT statements to only the fields needed for the SELECT
  • Reduced the things being saved to the db. In some cases, I was saving some very large text in the tables, which I thought would be taking a long time to save and process the text, but this wasn’t necessary to save this data, so I just omitted it
  • All db tables have appropriate indexes so SELECT happens quicker
  • In some areas where I display text content to the users (questions, articles, etc.), I switched from using a picture object to determine the size (height) of the label to an HTMLViewer with a scrollable label
  • There was more, but these are top of mind

I am curious about my pings/reconnects to the db tables. Basically, whenever the db needs to be touched (insert, update, delete, select), I do a Session.CheckConnectionContent, and if the db is Nil, then I reconnect. I have the two methods of these below. Can you take a look at them to see if this logic is correct? Of note, my db objects are also on the Session class as MySQLCommunityServer

Method CheckConnectionContent

dim b As Boolean
If mDbContent = Nil Then
b = ConnectToMySQLContent
Else
dim rs As RowSet
rs = mDbContent.SelectSQL(“SELECT 1 FROM DUAL”)
If rs = Nil Then
b = ConnectToMySQLContent
End If
End If

Method ConnectToMySQLContent As Boolean

dim connected As Boolean

Do
mDbContent = New MySQLCommunityServer

mDbContent.Host = app.kXojoHost
mDbContent.UserName = app.kXojoUN
mDbContent.Password = app.kXojoPW
mDbContent.DatabaseName = app.kXojoDBnameContent

connected = mDbContent.Connect()

If connected =  False Then
dim desc, err As String
desc = “DatabaseMethods.DBConnect.DBName.DatabaseError”
err = ", Cannot Contect to Database  " + Str(mDbContent.ErrorCode) + " - " + mDbContent.ErrorMessage

Return False

Else
Return True
End If
Loop until connected

I’m unsure if these methods are set up correctly, if they are creating/connecting to the dbs too frequently, and/or if they are contributing to the app restarts

I’ve been watching my memory usage throughout the recent days. It generally sits around 50MB, but after a recent app restart, it did shoot up to around 100MB. I do also notice when there are not a lot of people logged into the app, it seems to be ok. Yesterday and today, I had a lot of users entering the app at one time, and that is when I noticed a restart. These users are with a school. The school recently purchased the web app for its students, and they were all activating the app and going in to work on an assignment. And by “a lot”, this is only like a dozen users, not in the 100s

Does anyone have any thoughts on what to work on next? Anything I pointed out here scream to you as “that’s your problem right there”?

Same here.

My app has up to 50.000 daily active users in November and December. I’m still using 2024r3 because the app kept on restarting as soon as I built with 2025r2 /r3

connect raises an exception upon failure. Your code doesn’t appear to deal with this properly. It should look like this:

Try
db.Connect
MessageBox("Connected!")

Catch error As DatabaseException
MessageBox("Error connecting to the database: " + error.Message)

End Try

API 1.0 database connection was a function that returned a boolean representing success and did not raise exceptions. The code above is API 1.0 but you’re thinking API 2.0.

1 Like

I pushed through a new version this morning built again with 2024 R3 but also a small change with something I thought could also be problematic. About 5 hours and no restart, compared to yesterday’s 2025 R3 build with too many restarts to count. If it is the Xojo version, I hope they get this fixed finally as I feel we’re missing out on other important updates and features with the latest

Thanks for pointing that out! I thought I had added try/catch to all db calls but missed the ones in db connect! Added that safety net in this morning’s build

I am working on improving this today. Thanks for noticing this!

@Jeremie_L question for you about setting up Sentry in the web app. I’m currently only using this in my mobile apps. Is the setup basically the same? You posted in one of my posts a while back with some setup suggestions, which I bookmarked

Does the same API folder also work in web, and is this part in the App.Opening still accurate?

Dim sentryDSN As String = “https://thesentryURL+ID”

self.Sentry = jly_Sentry.GetInstance(sentryDSN)

Yes the setup is mostly the same.

But you should get the latest version of Xojo Sentry here: GitHub - jkleroy/XojoSentry: API for using https://sentry.io

I recommend looking at the web example in my repo to see all places where sentry can catch and report exceptions.

2 Likes

This is great! Thank you!

My web-app is up using both the current public build 2025r3 and the beta test build (2025r3.1 Beta) behind a load balancer. Have not seen any stability issues. Around 100+ users a day view the web pages, plus 1,000’s of calls to the API services it also runs. Very database (MySQL) driven not seeing any issues. Its got to be errors you are not catching do you have anything in “App.UnhandledException” event just to see if you are missing any errors?

Thanks for the info. Yes, I make use of UnhandledException in both the App class and Session class. I do receive notifications when an error happens, but nothing when the app decides to restart.

My App.UnhandledException:

If error <> Nil Then
Var type As String = Introspection.GetType(error).Name

Var msg As String = "App-Level Exception at " + DateTime.Now.ToString + EndOfLine + EndOfLine
msg = msg + "Type: " + Introspection.GetType(error).Name + EndOfLine
msg = msg + "Message: " + error.Message + EndOfLine + EndOfLine
msg = msg + “Stack:” + EndOfLine + String.FromArray(error.Stack, EndOfLine)

EmailMeError(msg)

End If

Return True

I have been going through bits at a time and making improvements I mentioned above, though nothing seems to help. I am continuing my efforts on updating problematic code. I did revert back to 2024 R3 a couple days ago and already see an improvement. Still restarting on me once, maybe twice a day, compared to every 30-60 minutes when the app was deployed in 2025 R3

@Jordan_Morris - what OS and version of it?

Are you using Xojo’s MySQL plugin or something like @Christian_Schmitz 's SQL plugin?

I think both items are relevant related to this stability issue.

Anthony

It is running on Ubuntu 22.04 LTS and i’m using the built in MySQL plugin. No 3rd party plugins in use at all.

1 Like

If you want notifications when your app restarts, You could use Pushover.

I use it in most of my apps to send important notifications directly to my iPhone and Apple Watch.

1 Like

Thanks @Jeremie_L ! I’ll check this out. Is it easy enough to set up in Xojo? I see they give recommendations for other languages, but, not surprisingly, not for Xojo

My 2 cents….

This has happened to me before…. In fact, every so often I see Xojo applications restarting in my Ubuntu servers. But it’s not very frequent, and I tend to blame the VPS because what I’ve observed is that most of the times it’s not just one, but ALL Xojo applications running on that server that restart at almost the same time when “the event” occurs.

Also, make sure your apps are behind some kind of protective layer, because otherwise they will be exposed to all kinds of attacks.
It’s worth taking a look at the app’s HTTPS requests log (if you have it) to see if it’s under stress.

Yes, it’s basically two lines of code for a simple message:

Var http as New URLonnection 
http.send("POST",...)

And an old blog post

1 Like

You may need to add some crash logging to the app, like the BugReporter included with MBS Plugins.

Use SignalHandlerMBS to catch crashes that don’t raise a normal exception. Otherwise you never know where crashes happen.

2 Likes