Vasaka
Vasaka

Reputation: 589

Meteor EADDRINUSE exception on remote method with Fibers

Below is my code in server/server.js file. When I call Meteor.apply('testMethod') I get Error: listen EADDRINUSE. I am running meteor app with meteorite, the only non-generic package installed is npm

var Fiber = Meteor.require('fibers');
var fiber = Fiber.current;
Meteor.methods({
    testMethod: function(){
        setTimeout(function(){fiber.run('test')}, 2000);
        res = Fiber.yield();
        console.log(res);
        return res;
    }
})

I know the most obvious solution here is to use Meteor's wrappers around fiber, but what I really want to implement is yielding from fiber on async call and then resuming within some event handler. And I have not found anything suitable for that.

Stack trace:

Error: listen EADDRINUSE
    at errnoException (net.js:901:11)
    at Server._listen2 (net.js:1039:14)
    at listen (net.js:1061:10)
    at net.js:1135:9
    at dns.js:72:18
    at process._tickCallback (node.js:415:13)

Upvotes: 2

Views: 240

Answers (1)

Dave
Dave

Reputation: 2576

I answered this on the Meteor IRC.

Move this line:

var fiber = Fiber.current;

into the first line of the 'testMethod' function. Like so:

var Fiber = Meteor.require('fibers');

Meteor.methods({
    testMethod: function(){
        var fiber = Fiber.current;
        setTimeout(function(){fiber.run('test')}, 2000);
        res = Fiber.yield();
        console.log(res);
        return res;
    }
});

I believe why you're experiencing this is because each user gets their own "fiber". So when the client calls the server, the current fiber is different than the fiber you declared in the outer scope.

Upvotes: 1

Related Questions