Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: unhandled Promise rejections in pipeline.exec [skip ci] #1466

Merged
merged 1 commit into from
Nov 24, 2021

Commits on Nov 23, 2021

  1. Fix unhandled Promise rejections in pipeline.exec

    (When failing to load lua scripts or in Redis.Cluster edge cases)
    
    1. Always return the same Promise in pipeline.exec.
    
       An example of why the original Promise should be returned, rather than
       a different Promise resolving to the original Promise:
    
       ```javascript
       process.on('unhandledRejection', (reason) => console.log('unhandledRejection', reason));
       const x = Promise.reject(new Error());
       x.catch((e) => console.log('caught x', e));
    
       const causesUnhandledRejection = Promise.resolve().then(() => x);
       ```
    2. In the negligible chance the `script exists`/`script load` command
       failed, give up, catch the rejected Promise with `finally`,
       and try to run the commands in the pipeline anyway.
       (e.g. networking issues, corrupted bytes, etc)
    
       This isn't the best approach, but it's hopefully better than an unhandled Promise rejection,
       resource/memory leak, or hanging request due to a redis Promise never
       resolving or rejecting for an individual command in this edge case.
    3. There are calls to `this.exec(...);` all over the Pipeline that don't
       check if the returned Promise is caught which I believe could lead to
       unhandled Promise rejections on retrying failed commands.
    
       Also, lib/autopipelining.js also called pipeline.exec without
       checking for errors.
    
       The fact there is now exactly one Promise instance that can be returned
       means that this no longer can cause unhandled Promise rejections.
       (see example snippet in commit description)
       (`standard-as-callback` is catching rejections)
    4. pipeline.exec can explicitly call reject for ioredis's Redis.Cluster
       client
    TysonAndre committed Nov 23, 2021
    Configuration menu
    Copy the full SHA
    946efee View commit details
    Browse the repository at this point in the history