mike-marcacci / node-redlock

A node.js redlock implementation for distributed, highly-available redis locks
MIT License
1.83k stars 172 forks source link

Promise never resolves #58

Closed joelwatson closed 5 years ago

joelwatson commented 5 years ago

node-relock version: 4.0.0 ioredis version: 4.11.2

Hi--

I'm currently trying to implement node-redlock into my application. When I run it locally, it works like a charm, doing exactly what I expect it to do.

However, when I put it into my QA environment (Amazon Elasticache cluster with 3 nodes), the lock promise never resolves, no error is thrown, and even the clientError handler does not fire. Any thoughts about what might be the root cause of this?

Here's my code

async isLocked(params) {
    const {id} = params;
    const resource = `my-resource-${id}`;
    const ttl = 5000;

    try {
        await redlock.lock(resource, ttl);
        // never returns
        return false;
    } catch (e) {
        console.log(e);
        return true;
    }
}

I appreciate your help--please let me know if you need additional information. Thanks!

mike-marcacci commented 5 years ago

Hi @joelwatson, this sounds a lot like #29 - are you by chance using the redis package? If so, try switching to ioredis which has built-in support for clusters.

EDIT: Err, looks like you already noted that you're running ioredis.

joelwatson commented 5 years ago

Closing this out. We had encryption turn on for our cluster in Elasticache, and weren't passing the tls option to the redis instance. The failure was completely on the redis side, so nothing to do here. But maybe this will help someone else out who has the same issue :)

joelwatson commented 5 years ago

@mike-marcacci Ah, was right in the middle of my close-comment! Thanks for the quick reply, turns out I needed some encryption settings for the redis instance. Thanks anyway!