question

Benjamin Bennett avatar image
Benjamin Bennett asked

Application.Quit isn't changing server from active to standby

I have a game server that is written in C#/Unity. The issue I'm having is that when the server calls Application.Quit it isn't leaving the Active state and going back to standby.

Is there something I'm missing in order to get this to work properly?

multiplayer
4 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Benjamin Bennett avatar image Benjamin Bennett commented ·

And to add to this:

When I run the server using the MockVMAgent locally it exits the server just the fine. I saw in another post that the status should change within a few seconds.

0 Likes 0 ·
Benjamin Bennett avatar image Benjamin Bennett commented ·

Running the following cloud script doesn't seem to shut down the server either even though the message is a success:

try {
    var request = {
      BuildId: args.buildId,
      SessionId: args.sessionId,
      Region: args.region,
    };

    var result = multiplayer.ShutdownMultiplayerServer(request);
  } catch (error) {
    log.error(error);
  }

  return "Success";


0 Likes 0 ·
Benjamin Bennett avatar image Benjamin Bennett commented ·

After another hour of banging my head on the keyboard I've found that the number of players being reported in the session is accurate to what I'm seeing on the dashboard. The code here is triggering because this is the only place I report player disconnect.

I feel like I must be missing something that I can't seem to find in the samples/docs/google

public void DisconnectPlayer(string playerId)
{
    var player = m_ConnectedPlayers.Find(x => x.PlayerId == playerId);
    m_ConnectedPlayers.Remove(player);
    PlayFabMultiplayerAgentAPI.UpdateConnectedPlayers(m_ConnectedPlayers);

    if (m_ConnectedPlayers.Count == 0)
    {
        StartCoroutine(ShutdownRoutine());
    }
}

private IEnumerator ShutdownRoutine()
{
    yield return new WaitForSeconds(5);
    Application.Quit();
}
0 Likes 0 ·
Benjamin Bennett avatar image Benjamin Bennett commented ·

I thought it was working, but it looks like the dashboard was just slow to update. Really no idea now lol

0 Likes 0 ·
Dimitris-Ilias Gkanatsios avatar image
Dimitris-Ilias Gkanatsios answered

Glad it's working. FWIW, servers never transition back to StandingBy after Active. Instead, when your game server process exists, we will cleanup the container, collect and archive the logs and create a new StandingBy server in its place.

If you want to quickly see the status of your servers, feel free to use our APIs, we've built this sample so you can easily use them.

MpsSamples/MpsAllocatorSample at master PlayFab/MpsSamples (github.com)

2 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Benjamin Bennett avatar image Benjamin Bennett commented ·

Hi! It's actually not working. My servers never manages to leave the 'Active' state. Yeah I saw that they get recycled. The problem I'm having is that after all my players leave the Application.Quit code isn't triggering the server to terminate. Instead it just sit's empty. I've verified the code is calling by running the server in the MockVMAgent and also in my own Digital Ocean Droplet. Not really sure why the process won't exit. Also running the Multiplayer API and calling ShutdownServer doesn't work on the active sessions.

0 Likes 0 ·
Benjamin Bennett avatar image Benjamin Bennett Benjamin Bennett commented ·

Thanks for the sample project. I actually added my own function here to try to manually shut the server down and it still won't go down.

static async Task ShutdownServer()
{
    var req = new PlayFab.MultiplayerModels.ShutdownMultiplayerServerRequest();
    string buildID = ReadBuildIDFromInput();
    var regions = await GetRegions(buildID);
    Console.WriteLine($"Enter region (options are {string.Join(",", regions)})");
    string region = Console.ReadLine();
    req.Region = region;
    req.BuildId = buildID;
    Console.Write("Session Id: ");
    req.SessionId = Console.ReadLine();
    var res = await PlayFabMultiplayerAPI.ShutdownMultiplayerServerAsync(req);
    if (res.Error != null)
    {
        Console.WriteLine(res.Error.ErrorMessage);
    }
    else
    {
        Console.WriteLine("Server scheduled for shutdown!");
    }
}
0 Likes 0 ·
Benjamin Bennett avatar image
Benjamin Bennett answered

Alright! So I did get it to work. It turns out that it takes ~25 minutes for the container to clean up. Which seems pretty bad. Is this normal?

7 comments
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Dimitris-Ilias Gkanatsios avatar image Dimitris-Ilias Gkanatsios commented ·

1. is Unity part of your start command? Unity process may exit but if created by something else (e.g. a powershell script) then if the powershell script is alive, then the container will be alive.

2. Normally we recommend the ShutdownMultiplayerServer API call only for urgent cases, e.g. if the server has hung. How did you measure the 25 minutes? In Game Manager or you used our APIs?

0 Likes 0 ·
Benjamin Bennett avatar image Benjamin Bennett Dimitris-Ilias Gkanatsios commented ·

I was using the sample you sent me to monitor it every minute. I'm not sure what you mean by part of my start command. It's just an executable I'm launching with "Server.exe". I'm not using PowerShell for my command launch to my knowledge.

0 Likes 0 ·
Benjamin Bennett avatar image Benjamin Bennett Dimitris-Ilias Gkanatsios commented ·

I think the 25 minutes was actually from the API call I made "ShutdownServer". It doesn't seem like the servers naturally clean up at all.

0 Likes 0 ·
Benjamin Bennett avatar image Benjamin Bennett commented ·

Hmm it does seem like it can clean up quicker, but I set my VM server instances to 10 per server and quickly hit the 10 limit before any had a chance to clean up

0 Likes 0 ·
Dimitris-Ilias Gkanatsios avatar image Dimitris-Ilias Gkanatsios Benjamin Bennett commented ·

for a general overview of our system, feel free to take a look at our quickstart video here PlayFab Multiplayer Hosted Servers part 1: Multiplayer Servers Quick Start - YouTube

We never recycle Active servers, that's why we monitor for game server exits (either by "regular" exit or crashes) and we'll create a new one asap.

0 Likes 0 ·
Benjamin Bennett avatar image Benjamin Bennett Dimitris-Ilias Gkanatsios commented ·

I see. Maybe it was just luck those servers were cleaned up quicker. I'm currently sitting at 10/10 Active for the last 10 to 15 minutes

0 Likes 0 ·
Show more comments

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.