Giray
Giray

Reputation: 105

Meteor framework free server crashes

Hi I just learned Meteor and developed a multiplayer game. For testing purposes, I deployed to the free server and each night we play the game with some friends, generally 20 online people. However, from time to time, website crashes and no data is coming in or out. It just freezes. I checked the client logs and server logs but nothing is there. When I refresh the page, it freezes on the loading template.

I use iron router for the loading screen:

Router.configure({
  layoutTemplate: 'main',
  notFoundTemplate: 'notFound',
  loadingTemplate: 'loading'
});

Router.route('/loading', {
  template : 'loading'
});

Router.route('/', {
  template : 'home',
  waitOn: function() {
    return [Meteor.subscribe('chat'),Meteor.subscribe('games'),Meteor.subscribe('users')];
  },  
  data : function(){
    return {
      chat : Chat.find({},{sort: {createdAt: 1}}),
      games : Games.find({},{sort: {createdAt: -1}}),
      users : Meteor.users.find({},{sort : {"status.online":-1}})
    }
  }
});

I have no idea about the problem. Sometimes it freezes on the main page, sometimes on the game page. For the game page, I am simplifying my code for you to understand.

There are 2 levels in the game: days and nights. It starts with the click of the game-creator and morning starts with a countdown. When countdown ends, night starts with a corresponding countdown. And it continues to loop until the game finishes. At the end of morning, there are some computations for the game and then it switches to night. Night is also the same.

For countdown purpose I use setTimeOut() function with a Fiber.

Meteor.methods({
    startGame : function(id){
        //some other code here
        //....

        //set timestamp of the end date
        var currentDate = new Date();
        console.log("currentDate: "+currentDate);
        if(night){ var interval = durationNight;}
        else{ var interval = durationMorning;}
        console.log("interval: "+interval);
        var endDate = currentDate.setSeconds(currentDate.getSeconds() + interval);
        console.log("endDate: "+endDate);

        Games.update({"_id" : id}, {$set : {"endTime" : endDate}});


        endLevelInternal[id] = setTimeout(function () {
            // // completed
            Fiber(function() { 
                console.log(id +' countdown completed');

                endLevelFlag[id] = true;

                if(endLevelFlag[id]){
                    endLevelFlag[id] = false;
                    Meteor.call('endLevel', id, function(){
                        endLevelFlag[id] = true;
                    });
                }
            }).run();  

        }, interval*1000);
    },

    endLevel : function(){
        //some other code here
        //...

        //
        if(!finished){
            Meteor.call('startGame', id);   
        }
    }
});

Template.game.events({
    'click .startGame' : function(evt, template){
        var flag = true;
        if(flag){
            flag = false;
            Meteor.call('startGame', template.data._id, function(){
                flag = true;
            });
        }
    }
});

I am not sure if the problem is because of the server code or because of the limitations of the free server (RAM or CPU).

Upvotes: 0

Views: 46

Answers (2)

Giray
Giray

Reputation: 105

For the ones who has the same problem. I just deployed my application from free server to Modulus and everything works fine now. So it must be something with the Meteor free server.

Upvotes: 0

Elie Steinbock
Elie Steinbock

Reputation: 5088

I suggest having a look at the Meteor logs, or deploying on some other platform that is production ready. One option is AWS or DigitalOcean using Meteor Up.

Upvotes: 1

Related Questions