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

retry(0) behavior changed in RxJS 7 and it is inconsitent with expectations (and documentation) #6358

Closed
vteslenko opened this issue May 4, 2021 · 1 comment · Fixed by #6359
Labels
7.x Issues and PRs for version 7.x bug Confirmed bug

Comments

@vteslenko
Copy link

vteslenko commented May 4, 2021

Bug Report

Current Behavior
Calling retry(0) will produce EMPTY obervable, so upstream will never be subscribed to.

retry(0) => 0 upstream subscriptions.
retry(1) => 1 upstream subscription and up to 1 resubscription.
retry(2) => 1 upstream subscription and up to 2 resubscriptions.

This breaks the scenario when retries can be turned on and off with a parameter.

Expected behavior
Calling retry(0) will produce an operator that subscribes to upstream only once.

retry(0) => 1 upstream subscription.
retry(1) => 1 upstream subscription and up to 1 resubscription.
retry(2) => 1 upstream subscription and up to 2 resubscriptions.

With previos behavior retry(param) where param=0 just turns retries off.

Reproduction

import { of } from "rxjs";
import { map, retry } from "rxjs/operators";

const source = of("World").pipe(
  map(x => `Hello ${x}!`),
  retry(0)
);

source.subscribe(console.log);

Ver 6.6.7: https://rxjs-fdhbub.stackblitz.io
You will see "Hello World" in the console once.

Ver 7.0.0: https://rxjs-xeymgx.stackblitz.io
The console will be empty.

Possible Solution
retry(0) should work as in 6.6.7, as it aligns with expectations that there always will be one upstream subscription.

@josepot
Copy link
Contributor

josepot commented May 4, 2021

Yep, I also think that this is a bug, because the following test currently fails:

  it('should not alter the source when the number of retries is smaller than 1', () => {
    const source = cold('--1-2-3-#');
    const subs =       ['^       !'];

    const expected =    '--1-2-3-#';
    const unsub =       '         !';

    const result = source.pipe(retry(0));

    expectObservable(result, unsub).toBe(expected);
    expectSubscriptions(source.subscriptions).toBe(subs);
  })

It's an easy fix. I'm pretty sure that the PR that I've opened fixes the issue.

@cartant cartant added 7.x Issues and PRs for version 7.x bug Confirmed bug labels May 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
7.x Issues and PRs for version 7.x bug Confirmed bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants