hemerajs / hemera

🔬 Writing reliable & fault-tolerant microservices in Node.js https://hemerajs.github.io/hemera/
MIT License
806 stars 70 forks source link

Strange behaviour with nested act calls and timeout errors #39

Closed acehko closed 7 years ago

acehko commented 7 years ago

Example code:

hemera.add({ topic : 'test', cmd : 'A' }, function(msg, reply) {
    console.log('A');
    setTimeout(() => reply(null, { ok : true }), 3000);
});

hemera.add({ topic : 'test', cmd : 'B' }, function(msg, reply) {

    console.log('B');
    this.act({ topic : 'test', cmd : 'A', timeout$ : 1000 }, function(err, res) {

       if ( err ) {
            console.log('A err');
            reply(err);
        } else {
            console.log('A res');
            reply(null, res);
        }

    });

});

hemera.act({ topic : 'test', cmd : 'B', timeout$ : 2000 }, (err, res) => {

    if ( err ) {
        console.log('B err');
    } else {
        console.log('B res');
    }

});

Output:

B
A
A err
B err
A res
B err

After the timeout, when the service replies with a response, the error gets forwarded to the first act call and not the response. Expected output would be:

B
A
A err
B err
A res
B res
StarpTech commented 7 years ago

@acehko thanks for reporting. I found the issue. The error must be reseted after a correct response https://github.com/hemerajs/hemera/commit/5f29dd1665c1f458651b9335a460424ae588c6e7. I fixed it with version 0.4.14. Try it.

Result is now

B
A
A err
B err
A res
B res
acehko commented 7 years ago

@StarpTech Works good now. Thank you

StarpTech commented 7 years ago

Also test was added https://github.com/hemerajs/hemera/commit/99ed1cea59f4106965016d7048ce7f35c37da7bf