[BUG] Server does not wait for all events to finish before exiting

Started by BigcaT_, Mar 02, 2015, 01:17 PM

Previous topic - Next topic

BigcaT_

Look, here is the code of OnScriptUnload:
function onScriptUnload()
{
for( local i=0; i <= GetMaxPlayers()-1; i++ )
{
local plr = FindPlayer(i);
if(plr) onPlayerPart(plr, 255);
}
DisconnectSQL( MainDatabase );
DisconnectSQL( PropsDB );
DisconnectSQL( acmds );
DisconnectSQL( IPdb );
DisconnectSQL( VehDB );
}

code of OnPlayerPart:

function onPlayerPart( player,  reason )
{
    SaveStats(player);
}
// OnPlayerPart is working..

code of SaveStats

function SaveStats( player )
{
local id = player.ID;
if ( status[ id ].IsReg == true )
{
QuerySQL( MainDatabase, "UPDATE Account SET Kills='" + player.Score + "', Deaths='" + status[ id ].Deaths + "', Cash='" + player.Cash + "' WHERE Name='" + player.Name.tolower() + "'" );
}
}

 When I close the server by myself, player stats can't save. why?

ali_vcmp

Try This

function SaveStats( player )
{
try{
 local id = player.ID;
 if ( status[ id ].IsReg == true )
 {
       QuerySQL( db, "UPDATE Account SET Kills='" + status[ id ].Kills + "', Deaths='" + status[ player.ID ].Deaths + "', Cash='" + status[ id ].Cash + "', Bank='" + status[ id ].Bank + "', Joins='" + status[id].Joins + "' WHERE Name='" + player.Name + "'" );
   print( "" + player.Name + " Stats Saved [" + player.ID + "]" );
 status[ id ] = null;
 }
}
   catch(e) print( "Save Stats Error: " + e );
}

Thijn

You should first question yourself if you need that many databases. You can create multiple tables inside one file, you know?

Have you tried adding debug text to know if your callback is actually called?

BigcaT_

Quote from: Thijn on Mar 02, 2015, 07:10 PMYou should first question yourself if you need that many databases. You can create multiple tables inside one file, you know?

Have you tried adding debug text to know if your callback is actually called?

Quote from: ali_vcmp on Mar 02, 2015, 04:16 PMTry This

function SaveStats( player )
{
try{
 local id = player.ID;
 if ( status[ id ].IsReg == true )
 {
       QuerySQL( db, "UPDATE Account SET Kills='" + status[ id ].Kills + "', Deaths='" + status[ player.ID ].Deaths + "', Cash='" + status[ id ].Cash + "', Bank='" + status[ id ].Bank + "', Joins='" + status[id].Joins + "' WHERE Name='" + player.Name + "'" );
   print( "" + player.Name + " Stats Saved [" + player.ID + "]" );
 status[ id ] = null;
 }
}
   catch(e) print( "Save Stats Error: " + e );
}
This still not working...

I  think the reason is that when I close my server, function onScriptUnload not call.
I put a message onscriptunload:


function onScriptUnload()
{
for( local i=0; i <= GetMaxPlayers()-1; i++ )
{
local plr = FindPlayer(i);
if(plr) onPlayerPart(plr, 255);
}
DisconnectSQL( MainDatabase );
DisconnectSQL( PropsDB );
DisconnectSQL( acmds );
DisconnectSQL( IPdb );
DisconnectSQL( VehDB );
print("Script Unloaded..");
}
but I can't see any message on the console when I close the server..

Thijn

I figured that was happening, well done finding out.

@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

.

Quote from: BigcaT_ on Mar 03, 2015, 07:29 AMI tried to use onServerStop() , but still not working when I close the server.

Yeah, there's a problem. Unfortunately, there's some issues when the server shuts down. And depending on the loaded modules you might not receive an event through that function. We've discussed this and stormeus promised to look into this for the next release.
.

BigcaT_

Quote from: S.L.C on Mar 03, 2015, 08:03 AM
Quote from: BigcaT_ on Mar 03, 2015, 07:29 AMI tried to use onServerStop() , but still not working when I close the server.

Yeah, there's a problem. Unfortunately, there some issues when the server shuts down. And depending on the loaded modules you might not receive an event through that function. We've discussed this and stormeus promised to look into this for the next release.
ok. Thanks for telling.

Stormeus

Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

I'm refiling this as a bug because the server is actually supposed to wait for events to finish.

BigcaT_

Quote from: stormeus on Mar 03, 2015, 07:04 PM
Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

I'm refiling this as a bug because the server is actually supposed to wait for events to finish.

Stormeus how can I use this now?

Stormeus

Quote from: BigcaT_ on Apr 19, 2015, 03:52 AM
Quote from: stormeus on Mar 03, 2015, 07:04 PM
Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

I'm refiling this as a bug because the server is actually supposed to wait for events to finish.

Stormeus how can I use this now?

Is this still an issue? The last server update should've given plugins a chance to shut down gracefully on both Linux and Windows.

BigcaT_

Quote from: stormeus on Apr 19, 2015, 05:53 AM
Quote from: BigcaT_ on Apr 19, 2015, 03:52 AM
Quote from: stormeus on Mar 03, 2015, 07:04 PM
Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

I'm refiling this as a bug because the server is actually supposed to wait for events to finish.

Stormeus how can I use this now?

Is this still an issue? The last server update should've given plugins a chance to shut down gracefully on both Linux and Windows.


stormeus a hacker always DDOS my server, and server can not call ShutDownServer(), it causes the player in server 's stats could not save, I hope to fix onScriptUnload, please!

Stormeus


ysc3839

Quote from: BigcaT_ on May 23, 2015, 01:56 PM
Quote from: stormeus on Apr 19, 2015, 05:53 AM
Quote from: BigcaT_ on Apr 19, 2015, 03:52 AM
Quote from: stormeus on Mar 03, 2015, 07:04 PM
Quote from: Thijn on Mar 03, 2015, 06:42 AM@Stormeus The server needs proper exit codes and needs to gracefully wait till all events are done processing :x

I'm refiling this as a bug because the server is actually supposed to wait for events to finish.

Stormeus how can I use this now?

Is this still an issue? The last server update should've given plugins a chance to shut down gracefully on both Linux and Windows.


stormeus a hacker always DDOS my server, and server can not call ShutDownServer(), it causes the player in server 's stats could not save, I hope to fix onScriptUnload, please!
It isn't a bug. You should save players' stats when players take some action(such as when a player kill other player, increases its "kill stats" and then save it immediately). This may solve most problem.

ℛḝξ☂

I may be a slow walker but I am always walking.

Stormeus