Microsoft Azure PlayFab logo
    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Add-ons
    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA
  • Runs on PlayFab
  • Pricing
    • Blog
    • Forums
    • Contact us
  • Sign up
  • Sign in
  • Ask a question
  • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges
  • Home /
  • API and SDK Questions /
This question was redirected from Application.Quit isn't changing server from active to the standby ?.
avatar image
Question by Benjamin Bennett · Aug 04, 2021 at 08:32 PM · multiplayer

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?

Comment

People who like this

0 Show 4
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benjamin Bennett · Aug 04, 2021 at 10:26 PM 0
Share

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.

avatar image Benjamin Bennett · Aug 04, 2021 at 10:27 PM 0
Share

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";


avatar image Benjamin Bennett · Aug 04, 2021 at 11:30 PM 0
Share

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();
}
avatar image Benjamin Bennett · Aug 05, 2021 at 02:06 AM 0
Share

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

2 Replies

· Add your reply
  • Sort: 
avatar image
Best Answer

Answer by Dimitris Gkanatsios · Aug 05, 2021 at 04:07 AM

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)

Comment

People who like this

0 Show 2 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Benjamin Bennett · Aug 05, 2021 at 04:21 AM 0
Share

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.

avatar image Benjamin Bennett Benjamin Bennett · Aug 05, 2021 at 04:57 AM 0
Share

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!");
    }
}
avatar image

Answer by Benjamin Bennett · Aug 05, 2021 at 06:04 AM

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?

Comment

People who like this

0 Show 7 · Share
10 |1200 characters needed characters left characters exceeded
▼
  • Viewable by all users
  • Viewable by moderators
  • Viewable by moderators and the original poster
  • Advanced visibility
Viewable by all users
avatar image Dimitris Gkanatsios · Aug 05, 2021 at 06:14 AM 0
Share

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?

avatar image Benjamin Bennett Dimitris Gkanatsios · Aug 05, 2021 at 06:33 AM 0
Share

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.

avatar image Benjamin Bennett Dimitris Gkanatsios · Aug 05, 2021 at 06:58 AM 0
Share

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.

avatar image Benjamin Bennett · Aug 05, 2021 at 06:15 AM 0
Share

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

avatar image Dimitris Gkanatsios Benjamin Bennett · Aug 05, 2021 at 06:19 AM 0
Share

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.

avatar image Benjamin Bennett Dimitris Gkanatsios · Aug 05, 2021 at 06:34 AM 0
Share

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

Show more comments

Your answer

Hint: You can notify a user about this post by typing @username

Up to 2 attachments (including images) can be used with a maximum of 524.3 kB each and 1.0 MB total.

Navigation

Spaces
  • General Discussion
  • API and SDK Questions
  • Feature Requests
  • PlayStream
  • Bugs
  • Add-on Marketplace
  • LiveOps
  • Follow this Question

    Answers Answers and Comments

    7 People are following this question.

    avatar image avatar image avatar image avatar image avatar image avatar image avatar image

    Related Questions

    Upload multiplayer asset 1 Answer

    How to know how many servers per machine on a single Virtual Machine. 1 Answer

    Is there a Unity plug-in for the PLayFab Party Xbox Live Helper Library (GDK in particular)? 1 Answer

    LocalVMAgent not working while running container mode for UE4 server build 2 Answers

    How to auto scale servers ? 1 Answer

    PlayFab

    • Multiplayer
    • LiveOps
    • Data & Analytics
    • Runs on PlayFab
    • Pricing

    Solutions

    • For Any Role

      • Engineer
      • Designer
      • Executive
      • Marketer
    • For Any Stage

      • Build
      • Improve
      • Grow
    • For Any Size

      • Solo
      • Indie
      • AAA

    Engineers

    • Documentation
    • Quickstarts
    • API Reference
    • SDKs
    • Usage Limits

    Resources

    • Forums
    • Contact us
    • Blog
    • Service Health
    • Terms of Service
    • Attribution

    Follow us

    • Facebook
    • Twitter
    • LinkedIn
    • YouTube
    • Sitemap
    • Contact Microsoft
    • Privacy & cookies
    • Terms of use
    • Trademarks
    • Safety & eco
    • About our ads
    • © Microsoft 2020
    • Anonymous
    • Sign in
    • Create
    • Ask a question
    • Create an article
    • Post an idea
    • Spaces
    • PlayStream
    • Feature Requests
    • Add-on Marketplace
    • Bugs
    • API and SDK Questions
    • General Discussion
    • LiveOps
    • Explore
    • Topics
    • Questions
    • Articles
    • Ideas
    • Users
    • Badges