Web App Standalone Crash - How to properly shutdown

Hello guys,

So i did some tests and it seems that if a Standalone app is killed while a shutdown is called then it always crashes, and the only error i get now is :

[quote]Unhandled NilObjectException
Message:

Stack:
RuntimeReraiseException
RuntimeRaiseException
RaiseNilObjectException
Session.Session.dbConnect%b%o<Session.Session>
Session.Session.Event_Open%%o<Session.Session>
WebSession._ExecuteEvent%%osA1v&b
WebSession._HandleEvent%%oso<_HTTPServer.HTTPRequestContext>
WebSession._HandleRequest%i8%oso<_HTTPServer.HTTPRequestContext>
WebApplication._HandleHTTPRequest%%oo<_HTTPServer.HTTPRequestContext>
_HTTPServer.HTTPRequestThread.Event_Run%%o<_HTTPServer.HTTPRequestThread>
RuntimeStackCheck
RuntimeTextFromOldString
crt_at_quick_exit
BaseThreadInitThunk
RtlUserThreadStart

[/quote]

The only way to fix this is simply build the app again and run it and it will work

Is there a proper way to close the databases and all to shutdown properly once you close the terminal app that kills the web app ? so far if it gets killed the WAL keeps opened the SQLite and goes crazy on the next start .

As a reference Standalone Web App, built with the latest XOJO and 64 Bit.

Thanks

Lets start here. What does “goes crazy” mean in this context?

Hi Greg,

If you mean the message then yes, once it crashes i cannot even start the app it pops the error interface with that message and thats it all over until i stop the app, delete it , build another version and put it in its place.

Or as least this is what i saw until now.

All I’m seeing there is that you’re calling do.Connect and then getting a NilObjectException from it. It might be interesting to check db.errormessage right there to see if there was an error.

But I digress. The correct way to shut down a web app is to call the Close method on each instance of the database that you have open (so you don’t end up with the WAL files), and then call Quit so it can do some cleanup.

If you have users connected, you might also want to give them some warning.

Here’s a link to the sqlite site which you might be interested in…

http://www.sqlite.com/transactional.html

That makes me think it’s not the database that’s your problem.

[quote=345417:@Greg O’Lone]All I’m seeing there is that you’re calling do.Connect and then getting a NilObjectException from it. It might be interesting to check db.errormessage right there to see if there was an error.

But I digress. The correct way to shut down a web app is to call the Close method on each instance of the database that you have open (so you don’t end up with the WAL files), and then call Quit so it can do some cleanup.

If you have users connected, you might also want to give them some warning.[/quote]
Well so far this is what that dbConnect does

[code]fmsDB = fmsDatabase.initDB(prefModule.DBFolder.Child(“hsapid.hsapidb”))

If Self.fmsDB <> Nil Then
If Self.fmsDB.Connect Then
Self.fmsDB.MultiUser = True

APIOnline = False


If App.fmsDB.AddDBStructure Then
  debugModule.Log("App.Open -> AddDBStructure.True. The structure was added to the database.")
Else
  debugModule.Log("App.Open -> AddDBStructure.False. Could Not add the structure to database. ")
End If

IsConnected = True
Return True

Else
IsConnected = False
Return False
End If
Else
IsConnected = False
Return False

APIOnline = False
End If[/code]

So i have no idea where it could be wrong as it is simple logics , and it returns True or False, that`s it .

Maybe i`m missing something.

Well one thing is that multiuser should be set before you connect…

Well then please update the docs as i followed the sample there , same thing in the Offline Docs.

Sample URL

And it clearly states :

Please see as well the description

[quote]Notes

If you want to use WAL, you need to set this property to True after connecting to the database by calling Connect.[/quote]

[code]Dim dbFile As GetFolderItem(“MyDB.sqlite”)

Dim db As New SQLiteDatabase
db.DatabaseFile = dbFile

If db.Connect Then
db.MultiUser = True

MsgBox(“Connected to database.”)
Else
MsgBox("Connection error: " + db.ErrorMessage)
End If
[/code]

Please let me know which is correct now so that i can update on my side.

Thanks

Hello Greg,

I did the think you asked and i get same error, and this time i build it with Xojo 2017R2 so even if i put the statement before connect or after connect i get the same thing, i always have to recompile the app and put it back as if i restart the pc or restart the app it keeps on crashing .

This time i changed to 64 Bits so same issue.

Any other ideas ?

Thanks.

[quote=345739:@Aurelian Negrea]Hello Greg,

I did the think you asked and i get same error, and this time i build it with Xojo 2017R2 so even if i put the statement before connect or after connect i get the same thing, i always have to recompile the app and put it back as if i restart the pc or restart the app it keeps on crashing .

This time i changed to 64 Bits so same issue.

Any other ideas ?

Thanks.[/quote]
My statement about multiuser was one of experience, not documentation, but as soon as the guys get together for today’s meeting, I’ll try to get a definitive answer.

As for more ideas, from your statements, it sounds like you’re getting some sort of program corruption when it crashes, but I find that extremely hard to believe as I’ve never seen this happen with a web app before.

Are you sure that the whole app needs to be replaced? Could it be that just the database is corrupt?

Just out of curiosity, when you get into this state, you might want to try opening that database file with another app to see if that’s possible… that might confirm the data corruption. If it opens and you can operate on it, it may just be a locking issue.

Another possibility… when assigning the folderitem to the database, you might check the following conditions:
0. Folderitem.Parent.IsWritable =True
0. FolderItem.IsWritable =True
0. FolderItem.IsReadable = True

[quote=345776:@Greg O’Lone]My statement about multiuser was one of experience, not documentation, but as soon as the guys get together for today’s meeting, I’ll try to get a definitive answer.

As for more ideas, from your statements, it sounds like you’re getting some sort of program corruption when it crashes, but I find that extremely hard to believe as I’ve never seen this happen with a web app before.

Are you sure that the whole app needs to be replaced? Could it be that just the database is corrupt?

Just out of curiosity, when you get into this state, you might want to try opening that database file with another app to see if that’s possible… that might confirm the data corruption. If it opens and you can operate on it, it may just be a locking issue.

Another possibility… when assigning the folderitem to the database, you might check the following conditions:
0. Folderitem.Parent.IsWritable =True
0. FolderItem.IsWritable =True
0. FolderItem.IsReadable = True[/quote]

Hello Greg,

Well so far if it was a DB corruption normally the new compiled app will not be able to open the database and to see the data, so far once i put the new compiled app it works smooth, so i still have no clue why it happens that one but still under process of debugging that .

Now to come back to our title , it seems that the session gets killed only after the browser closes so there is no way for me to actually close properly the database unless i tell all the users to close their window which is hard as some of them might not be in the office or in front of the pc but they let their interface on.

So is it very hard for me to properly close the database .

What i did was, creating a custom class with a timer super and putting there the code to kill the sessions and to close the db but for some reasons does not work .

So when i press a button in the admin , Maintenance on, it fires the timer.

Here is the code :

[code]If App.MaintenanceMode Then

If IsRunning = False Then
IsRunning = True
For i As Integer = 0 To App.SessionCount-1
debugModule.Log(“tmrST - Username : " + App.SessionAtIndex(i).Cookies.Value(“username”) + " was online.”)

  App.SessionAtIndex(i).MsgBox("We are shutting down now.")
  App.SessionAtIndex(i).Quit
Next

If App.SessionCount = 0 Then
  debugModule.Log("tmrST - Not more sessions, should Quit")
  Session.fmsDB.Close
  
  IsRunning = False
  
  App.Quit
  
Else
  debugModule.Log("tmrST - There are still " + App.SessionCount.ToText + " sessions active.")
  Return
End If

End If
End If
[/code]

So in the debugging once is killing all the sessions still have the browser page opened, once this is closed manually then the app finally gets closed and the db gets cleaned up.

One issue that i noticed is that on MAC it works smooth after all the tests while on windows it does not close the db at all some times so something hangs there.

I will check as well what you suggested and see what i get.

Any update on the multi user location ?

Thanks again.

Another thing will be the timeouts , on MAC i set for session a timeout of 150 , after that period the windows on MAC go on Login screen, on Windows, Internet Explorer and Chrome they stay like that forever without signing off. I let on purpose yesterday when i left the page on and after 18 hours the page was still there without signing off on Windows (IE/Chrome) So Something fishy there as well.