flamescape / SourceQuery

A Source Server Query protocol implementation for node.js
9 stars 3 forks source link

Random Error #4

Open busheezy opened 8 years ago

busheezy commented 8 years ago
/home/bush/status/node_modules/sourcequery/sourcequery.js:127
        for (var i = 0; i < values.length; i++) {
                                  ^
TypeError: Cannot read property 'length' of undefined
    at combine (/home/bush/status/node_modules/sourcequery/sourcequery.js:127:35)
    at /home/bush/status/node_modules/sourcequery/sourcequery.js:239:34
    at EventEmitter.relayResponse (/home/bush/status/node_modules/sourcequery/sourcequery.js:113:17)
    at emitTwo (events.js:87:13)
    at EventEmitter.emit (events.js:172:7)
    at EventEmitter.SQUnpacker.readMessage (/home/bush/status/node_modules/sourcequery/sourcequery.js:70:9)
    at emitTwo (events.js:87:13)
    at Socket.emit (events.js:172:7)
---------------------------------------------
    at SendWrap.callback (/home/bush/status/node_modules/sourcequery/sourcequery.js:121:27)
    at SendWrap.afterSend [as oncomplete] (dgram.js:346:8)

This has been ruining my day for weeks.

mikuso commented 8 years ago

@busheezy Which version of node are you running? Which method is failing? Can you provide an example of a server address which causes this failure?

busheezy commented 8 years ago
var async = require('async');
var SourceQuery = require('sourcequery');

function updateServers(){
  var servers = [
    {
      ip: 'duels3.joshog.com',
      port: 27015
    },
    {
      ip: 'duels2.joshog.com',
      port: 27015
    },
    {
      ip: 'duels1.joshog.com',
      port: 27015
    },
    {
      ip: 'surf1.joshog.com',
      port: 27015
    },
    {
      ip: 'surf2.joshog.com',
      port: 27015
    },
    {
      ip: 'mg.joshog.com',
      port: 27015
    },
    {
      ip: 'pistoldm.joshog.com',
      port: 27015
    },
    {
      ip: 'dm.joshog.com',
      port: 27015
    },
    {
      ip: 'bhop.joshog.com',
      port: 27015
    },
    {
      ip: 'retakes.joshog.com',
      port: 27015
    }
  ];

  async.map(servers, getInfo, function (err, results){
    console.log(results);
  });
}

function getInfo(server, cb){
  var sq = new SourceQuery(2000);
  sq.open(server.ip, server.port);
  async.series([
    function (callback){
      sq.getInfo(function (err, info){
        server.info = info;
        callback(null, 1);
      });
    },
    function (callback){
      sq.getPlayers(function (err, players){
        server.players = players;
        callback(null, 2);
      });
    },
    function (callback){
      sq.close(function(){
        console.log('This does not seem to run but sq.close keeps it from never closing.');
      });
      callback(null, 3);  // have to put down here to make sure it runs.
    }
  ],
    function(err, results){
      cb(null, server);
    }
  );
}

setInterval(updateServers, 10 * 1000);

Here is a bit of the code I was using. You might want to wait until we are busier but it seemed to appear randomly. I was running node 5 and node 5.3. It would spit out those errors at me and lock up my site. I reduced it all the way down to the code above just for testing and it would still appear. The bug doesn't happen all of the time. I wasn't able to tell if a certain server was causing it.

webman commented 6 years ago

This problem is isset yet. How to fix it?

busheezy commented 6 years ago

I'm using a different library. I would suggest that you do the same. SourceQuery hasn't had an update in five years.

webman commented 6 years ago

@busheezy Can you get link to that library?

busheezy commented 6 years ago

https://github.com/sonicsnes/node-gamedig