Repository: celery/celery

Issue:
Chord join timeout is still hardcoded somewhere
<!--
Please fill this template entirely and do not erase parts of it.
We reserve the right to close without a response
bug reports which are incomplete.
-->
# Checklist
<!--
To check an item on the list replace [ ] with [x].
-->
- [x] I have verified that the issue exists against the `master` branch of Celery.
- [ ] This has already been asked to the [discussion group](https://groups.google.com/forum/#!forum/celery-users) first.
- [x] I have read the relevant section in the
  [contribution guide](http://docs.celeryproject.org/en/latest/contributing.html#other-bugs)
  on reporting bugs.
- [x] I have checked the [issues list](https://github.com/celery/celery/issues?q=is%3Aissue+label%3A%22Issue+Type%3A+Bug+Report%22+-label%3A%22Category%3A+Documentation%22)
  for similar or identical bug reports.
- [x] I have checked the [pull requests list](https://github.com/celery/celery/pulls?q=is%3Apr+label%3A%22PR+Type%3A+Bugfix%22+-label%3A%22Category%3A+Documentation%22)
  for existing proposed fixes.
- [x] I have checked the [commit log](https://github.com/celery/celery/commits/master)
  to find out if the bug was already fixed in the master branch.
- [x] I have included all related issues and possible duplicate issues
  in this issue (If there are none, check this box anyway).

## Mandatory Debugging Information

- [ ] I have included the output of ``celery -A proj report`` in the issue.
    (if you are not able to do this, then at least specify the Celery
     version affected).
- [x] I have verified that the issue exists against the `master` branch of Celery.
- [ ] I have included the contents of ``pip freeze`` in the issue.
- [ ] I have included all the versions of all the external dependencies required
  to reproduce this bug.

## Optional Debugging Information
<!--
Try some of the below if you think they are relevant.
It will help us figure out the scope of the bug and how many users it affects.
-->
- [ ] I have tried reproducing the issue on more than one Python version
  and/or implementation.
- [ ] I have tried reproducing the issue on more than one message broker and/or
  result backend.
- [ ] I have tried reproducing the issue on more than one version of the message
  broker and/or result backend.
- [ ] I have tried reproducing the issue on more than one operating system.
- [ ] I have tried reproducing the issue on more than one workers pool.
- [ ] I have tried reproducing the issue with autoscaling, retries,
  ETA/Countdown & rate limits disabled.
- [x] I have tried reproducing the issue after downgrading
  and/or upgrading Celery and its dependencies.

## Related Issues and Possible Duplicates
<!--
Please make sure to search and mention any related issues
or possible duplicates to this issue as requested by the checklist above.

This may or may not include issues in other repositories that the Celery project
maintains or other repositories that are dependencies of Celery.

If you don't know how to mention issues, please refer to Github's documentation
on the subject: https://help.github.com/en/articles/autolinked-references-and-urls#issues-and-pull-requests
-->

#### Related Issues

- Allow GroupResult.join timeout to be configurable in celery.chord_unlock (#5349)

#### Possible Duplicates

- None

## Environment & Settings
<!-- Include the contents of celery --version below -->
**Celery version**: master
<!-- Include the output of celery -A proj report below -->
<details>
<summary><b><code>celery report</code> Output:</b></summary>
<p>

```
```

</p>
</details>

# Steps to Reproduce

Look through celery source code to find out that base and redis result backend `join_func` is called with hardcoded timeout:
[base.py](https://github.com/celery/celery/blob/master/celery/backends/base.py#L930)
```
                with allow_join_result():
                    ret = j(timeout=3.0, propagate=True)
```

[redis.py](https://github.com/celery/celery/blob/master/celery/backends/redis.py#L471)
```
                    with allow_join_result():
                        resl = join_func(timeout=3.0, propagate=True)
```

## Required Dependencies
<!-- Please fill the required dependencies to reproduce this issue -->
* **Minimal Python Version**: N/A or Unknown
* **Minimal Celery Version**: N/A or Unknown
* **Minimal Kombu Version**: N/A or Unknown
* **Minimal Broker Version**: N/A or Unknown
* **Minimal Result Backend Version**: N/A or Unknown
* **Minimal OS and/or Kernel Version**: N/A or Unknown
* **Minimal Broker Client Version**: N/A or Unknown
* **Minimal Result Backend Client Version**: N/A or Unknown

### Python Packages
<!-- Please fill the contents of pip freeze below -->
<details>
<summary><b><code>pip freeze</code> Output:</b></summary>
<p>

```
```

</p>
</details>

### Other Dependencies
<!--
Please provide system dependencies, configuration files
and other dependency information if applicable
-->
<details>
<p>
N/A
</p>
</details>

## Minimally Reproducible Test Case
<!--
Please provide a reproducible test case.
Refer to the Reporting Bugs section in our contribution guide.

We prefer submitting test cases in the form of a PR to our integration test suite.
If you can provide one, please mention the PR number below.
If not, please attach the most minimal code example required to reproduce the issue below.
If the test case is too large, please include a link to a gist or a repository below.
-->

<details>
<p>

```python
```

</p>
</details>

# Expected Behavior
<!-- Describe in detail what you expect to happen -->

I expect that `result_chord_join_timeout` will affect timeout while working with chord parts.

# Actual Behavior
<!--
Describe in detail what actually happened.
Please include a backtrace and surround it with triple backticks (```).
In addition, include the Celery daemon logs, the broker logs,
the result backend logs and system logs below if they will help us debug
the issue.
-->

With very large chords there are sudden timeouts which can't be eliminated by changing appropriate configuration option. 


Discussion:

Resolving patch:
diff --git a/celery/backends/base.py b/celery/backends/base.py
--- a/celery/backends/base.py
+++ b/celery/backends/base.py
@@ -928,7 +928,9 @@ def on_chord_part_return(self, request, state, result, **kwargs):
             j = deps.join_native if deps.supports_native_join else deps.join
             try:
                 with allow_join_result():
-                    ret = j(timeout=3.0, propagate=True)
+                    ret = j(
+                        timeout=app.conf.result_chord_join_timeout,
+                        propagate=True)
             except Exception as exc:  # pylint: disable=broad-except
                 try:
                     culprit = next(deps._failed_join_report())
diff --git a/celery/backends/redis.py b/celery/backends/redis.py
--- a/celery/backends/redis.py
+++ b/celery/backends/redis.py
@@ -469,7 +469,10 @@ def on_chord_part_return(self, request, state, result,
                         else header_result.join
                     )
                     with allow_join_result():
-                        resl = join_func(timeout=3.0, propagate=True)
+                        resl = join_func(
+                            timeout=app.conf.result_chord_join_timeout,
+                            propagate=True
+                        )
                 else:
                     # Otherwise simply extract and decode the results we
                     # stashed along the way, which should be faster for large


Test patch:
diff --git a/t/unit/backends/test_base.py b/t/unit/backends/test_base.py
--- a/t/unit/backends/test_base.py
+++ b/t/unit/backends/test_base.py
@@ -786,6 +786,18 @@ def callback(result):
             callback.backend.fail_from_current_stack = Mock()
             yield task, deps, cb
 
+    def test_chord_part_return_timeout(self):
+        with self._chord_part_context(self.b) as (task, deps, _):
+            try:
+                self.app.conf.result_chord_join_timeout += 1.0
+                self.b.on_chord_part_return(task.request, 'SUCCESS', 10)
+            finally:
+                self.app.conf.result_chord_join_timeout -= 1.0
+
+            self.b.expire.assert_not_called()
+            deps.delete.assert_called_with()
+            deps.join_native.assert_called_with(propagate=True, timeout=4.0)
+
     def test_chord_part_return_propagate_set(self):
         with self._chord_part_context(self.b) as (task, deps, _):
             self.b.on_chord_part_return(task.request, 'SUCCESS', 10)
diff --git a/t/unit/backends/test_redis.py b/t/unit/backends/test_redis.py
--- a/t/unit/backends/test_redis.py
+++ b/t/unit/backends/test_redis.py
@@ -1012,6 +1012,21 @@ def test_apply_chord_complex_header(self):
         mock_header_result.save.assert_called_once_with(backend=self.b)
         mock_header_result.save.reset_mock()
 
+    def test_on_chord_part_return_timeout(self, complex_header_result):
+        tasks = [self.create_task(i) for i in range(10)]
+        random.shuffle(tasks)
+        try:
+            self.app.conf.result_chord_join_timeout += 1.0
+            for task, result_val in zip(tasks, itertools.cycle((42, ))):
+                self.b.on_chord_part_return(
+                    task.request, states.SUCCESS, result_val,
+                )
+        finally:
+            self.app.conf.result_chord_join_timeout -= 1.0
+
+        join_func = complex_header_result.return_value.join_native
+        join_func.assert_called_once_with(timeout=4.0, propagate=True)
+
     @pytest.mark.parametrize("supports_native_join", (True, False))
     def test_on_chord_part_return(
         self, complex_header_result, supports_native_join,