diff --git a/kafka/coordinator/base.py b/kafka/coordinator/base.py
index 30b9c40..24412c9 100644
--- a/kafka/coordinator/base.py
+++ b/kafka/coordinator/base.py
@@ -377,19 +377,23 @@ class BaseCoordinator(object):
                 # before the pending rebalance has completed.
                 if self.join_future is None:
                     self.state = MemberState.REBALANCING
-                    self.join_future = self._send_join_group_request()
+                    future = self._send_join_group_request()
+
+                    self.join_future = future  # this should happen before adding callbacks
 
                     # handle join completion in the callback so that the
                     # callback will be invoked even if the consumer is woken up
                     # before finishing the rebalance
-                    self.join_future.add_callback(self._handle_join_success)
+                    future.add_callback(self._handle_join_success)
 
                     # we handle failures below after the request finishes.
                     # If the join completes after having been woken up, the
                     # exception is ignored and we will rejoin
-                    self.join_future.add_errback(self._handle_join_failure)
+                    future.add_errback(self._handle_join_failure)
+
+                else:
+                    future = self.join_future
 
-                future = self.join_future
                 self._client.poll(future=future)
 
                 if future.failed():

AttributeError: 'NoneType' object has no attribute 'failed'
Via #1315 comments:
```
Traceback (most recent call last):
  File "./client_staging.py", line 53, in <module>
    results = consumer.poll(timeout_ms=10000, max_records=1)
  File "/usr/local/lib/python2.7/dist-packages/kafka/consumer/group.py", line 601, in poll
    records = self._poll_once(remaining, max_records)
  File "/usr/local/lib/python2.7/dist-packages/kafka/consumer/group.py", line 621, in _poll_once
    self._coordinator.poll()
  File "/usr/local/lib/python2.7/dist-packages/kafka/coordinator/consumer.py", line 271, in poll
    self.ensure_active_group()
  File "/usr/local/lib/python2.7/dist-packages/kafka/coordinator/base.py", line 401, in ensure_active_group
    if future.failed():
AttributeError: 'NoneType' object has no attribute 'failed'
```
diff --git a/test/test_coordinator.py b/test/test_coordinator.py
index 7dc0e04..f567369 100644
--- a/test/test_coordinator.py
+++ b/test/test_coordinator.py
@@ -620,3 +620,16 @@ def test_lookup_coordinator_failure(mocker, coordinator):
                         return_value=Future().failure(Exception('foobar')))
     future = coordinator.lookup_coordinator()
     assert future.failed()
+
+
+def test_ensure_active_group(mocker, coordinator):
+    coordinator._subscription.subscribe(topics=['foobar'])
+    mocker.patch.object(coordinator, 'coordinator_unknown', return_value=False)
+    mocker.patch.object(coordinator, '_send_join_group_request', return_value=Future().success(True))
+    mocker.patch.object(coordinator, 'need_rejoin', side_effect=[True, True, False])
+    mocker.patch.object(coordinator, '_on_join_complete')
+    mocker.patch.object(coordinator, '_heartbeat_thread')
+
+    coordinator.ensure_active_group()
+
+    coordinator._send_join_group_request.assert_called_once_with()

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-catchlog pytest-sugar pytest-mock mock python-snappy lz4 xxhash
apt-get update apt-get install -y libsnappy-dev
3.6
docs/requirements.txt
pytest --no-header -rA --tb=line --color=no -p no:cacheprovider -W ignore::DeprecationWarning
alabaster==0.7.13
attrs==22.2.0
Babel==2.11.0
certifi==2021.5.30
charset-normalizer==2.0.12
coverage==6.2
cramjam==2.5.0
docutils==0.18.1
idna==3.10
imagesize==1.4.1
importlib-metadata==4.8.3
iniconfig==1.1.1
Jinja2==3.0.3
-e git+https://github.com/dpkp/kafka-python.git@a69320b8e3199fa9d7cfa3947a242e699a045c3b#egg=kafka_python
lz4==3.1.10
MarkupSafe==2.0.1
mock==5.2.0
packaging==21.3
pluggy==1.0.0
pockets==0.9.1
py==1.11.0
Pygments==2.14.0
pyparsing==3.1.4
pytest==7.0.1
pytest-catchlog==1.2.2
pytest-cov==4.0.0
pytest-mock==3.6.1
pytest-sugar==0.9.6
python-snappy==0.7.3
pytz==2025.2
requests==2.27.1
six==1.17.0
snowballstemmer==2.2.0
Sphinx==5.3.0
sphinx-rtd-theme==2.0.0
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==2.0.0
sphinxcontrib-jquery==4.1
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-napoleon==0.7
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.5
termcolor==1.1.0
tomli==1.2.3
typing_extensions==4.1.1
urllib3==1.26.20
xxhash==3.2.0
zipp==3.6.0

name: kafka-python
channels:
  - defaults
  - https://repo.anaconda.com/pkgs/main
  - https://repo.anaconda.com/pkgs/r
  - conda-forge
dependencies:
  - _libgcc_mutex=0.1=main
  - _openmp_mutex=5.1=1_gnu
  - ca-certificates=2025.2.25=h06a4308_0
  - certifi=2021.5.30=py36h06a4308_0
  - ld_impl_linux-64=2.40=h12ee557_0
  - libffi=3.3=he6710b0_2
  - libgcc-ng=11.2.0=h1234567_1
  - libgomp=11.2.0=h1234567_1
  - libstdcxx-ng=11.2.0=h1234567_1
  - ncurses=6.4=h6a678d5_0
  - openssl=1.1.1w=h7f8727e_0
  - pip=21.2.2=py36h06a4308_0
  - python=3.6.13=h12debd9_1
  - readline=8.2=h5eee18b_0
  - setuptools=58.0.4=py36h06a4308_0
  - sqlite=3.45.3=h5eee18b_0
  - tk=8.6.14=h39e8969_0
  - wheel=0.37.1=pyhd3eb1b0_0
  - xz=5.6.4=h5eee18b_1
  - zlib=1.2.13=h5eee18b_1
  - pip:
      - alabaster==0.7.13
      - attrs==22.2.0
      - babel==2.11.0
      - charset-normalizer==2.0.12
      - coverage==6.2
      - cramjam==2.5.0
      - docutils==0.18.1
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - jinja2==3.0.3
      - lz4==3.1.10
      - markupsafe==2.0.1
      - mock==5.2.0
      - packaging==21.3
      - pluggy==1.0.0
      - pockets==0.9.1
      - py==1.11.0
      - pygments==2.14.0
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytest-catchlog==1.2.2
      - pytest-cov==4.0.0
      - pytest-mock==3.6.1
      - pytest-sugar==0.9.6
      - python-snappy==0.7.3
      - pytz==2025.2
      - requests==2.27.1
      - six==1.17.0
      - snowballstemmer==2.2.0
      - sphinx==5.3.0
      - sphinx-rtd-theme==2.0.0
      - sphinxcontrib-applehelp==1.0.2
      - sphinxcontrib-devhelp==1.0.2
      - sphinxcontrib-htmlhelp==2.0.0
      - sphinxcontrib-jquery==4.1
      - sphinxcontrib-jsmath==1.0.1
      - sphinxcontrib-napoleon==0.7
      - sphinxcontrib-qthelp==1.0.3
      - sphinxcontrib-serializinghtml==1.1.5
      - termcolor==1.1.0
      - tomli==1.2.3
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - xxhash==3.2.0
      - zipp==3.6.0
prefix: /opt/conda/envs/kafka-python

test/test_coordinator.py::test_ensure_active_group
test/test_coordinator.py::test_init test/test_coordinator.py::test_autocommit_enable_api_version[api_version0] test/test_coordinator.py::test_autocommit_enable_api_version[api_version1] test/test_coordinator.py::test_autocommit_enable_api_version[api_version2] test/test_coordinator.py::test_autocommit_enable_api_version[api_version3] test/test_coordinator.py::test_protocol_type test/test_coordinator.py::test_group_protocols test/test_coordinator.py::test_pattern_subscription[api_version0] test/test_coordinator.py::test_pattern_subscription[api_version1] test/test_coordinator.py::test_pattern_subscription[api_version2] test/test_coordinator.py::test_pattern_subscription[api_version3] test/test_coordinator.py::test_lookup_assignor test/test_coordinator.py::test_join_complete test/test_coordinator.py::test_subscription_listener test/test_coordinator.py::test_subscription_listener_failure test/test_coordinator.py::test_perform_assignment test/test_coordinator.py::test_on_join_prepare test/test_coordinator.py::test_need_rejoin test/test_coordinator.py::test_refresh_committed_offsets_if_needed test/test_coordinator.py::test_fetch_committed_offsets test/test_coordinator.py::test_close test/test_coordinator.py::test_commit_offsets_async test/test_coordinator.py::test_commit_offsets_sync test/test_coordinator.py::test_maybe_auto_commit_offsets_sync[api_version0-foobar-True-None-False-False-True-False] test/test_coordinator.py::test_maybe_auto_commit_offsets_sync[api_version1-foobar-True-None-True-True-False-False] test/test_coordinator.py::test_maybe_auto_commit_offsets_sync[api_version2-foobar-True-None-True-True-False-False] test/test_coordinator.py::test_maybe_auto_commit_offsets_sync[api_version3-foobar-False-None-False-False-False-False] test/test_coordinator.py::test_maybe_auto_commit_offsets_sync[api_version4-foobar-True-error4-True-True-True-False] test/test_coordinator.py::test_maybe_auto_commit_offsets_sync[api_version5-foobar-True-error5-True-True-True-False] test/test_coordinator.py::test_maybe_auto_commit_offsets_sync[api_version6-foobar-True-error6-True-True-True-False] test/test_coordinator.py::test_maybe_auto_commit_offsets_sync[api_version7-foobar-True-error7-True-True-False-True] test/test_coordinator.py::test_maybe_auto_commit_offsets_sync[api_version8-foobar-True-None-True-True-False-False] test/test_coordinator.py::test_maybe_auto_commit_offsets_sync[api_version9-None-True-None-False-False-True-False] test/test_coordinator.py::test_send_offset_commit_request_fail test/test_coordinator.py::test_send_offset_commit_request_versions[api_version0-OffsetCommitRequest_v0] test/test_coordinator.py::test_send_offset_commit_request_versions[api_version1-OffsetCommitRequest_v1] test/test_coordinator.py::test_send_offset_commit_request_versions[api_version2-OffsetCommitRequest_v2] test/test_coordinator.py::test_send_offset_commit_request_failure test/test_coordinator.py::test_send_offset_commit_request_success test/test_coordinator.py::test_handle_offset_commit_response[response0-GroupAuthorizationFailedError-False-False] test/test_coordinator.py::test_handle_offset_commit_response[response1-OffsetMetadataTooLargeError-False-False] test/test_coordinator.py::test_handle_offset_commit_response[response2-InvalidCommitOffsetSizeError-False-False] test/test_coordinator.py::test_handle_offset_commit_response[response3-GroupLoadInProgressError-False-False] test/test_coordinator.py::test_handle_offset_commit_response[response4-GroupCoordinatorNotAvailableError-True-False] test/test_coordinator.py::test_handle_offset_commit_response[response5-NotCoordinatorForGroupError-True-False] test/test_coordinator.py::test_handle_offset_commit_response[response6-RequestTimedOutError-True-False] test/test_coordinator.py::test_handle_offset_commit_response[response7-CommitFailedError-False-True] test/test_coordinator.py::test_handle_offset_commit_response[response8-CommitFailedError-False-True] test/test_coordinator.py::test_handle_offset_commit_response[response9-CommitFailedError-False-True] test/test_coordinator.py::test_handle_offset_commit_response[response10-InvalidTopicError-False-False] test/test_coordinator.py::test_handle_offset_commit_response[response11-TopicAuthorizationFailedError-False-False] test/test_coordinator.py::test_send_offset_fetch_request_fail test/test_coordinator.py::test_send_offset_fetch_request_versions[api_version0-OffsetFetchRequest_v0] test/test_coordinator.py::test_send_offset_fetch_request_versions[api_version1-OffsetFetchRequest_v1] test/test_coordinator.py::test_send_offset_fetch_request_versions[api_version2-OffsetFetchRequest_v1] test/test_coordinator.py::test_send_offset_fetch_request_failure test/test_coordinator.py::test_send_offset_fetch_request_success test/test_coordinator.py::test_handle_offset_fetch_response[response0-GroupLoadInProgressError-False] test/test_coordinator.py::test_handle_offset_fetch_response[response1-NotCoordinatorForGroupError-True] test/test_coordinator.py::test_handle_offset_fetch_response[response2-TopicAuthorizationFailedError-False] test/test_coordinator.py::test_handle_offset_fetch_response[response3-None-False] test/test_coordinator.py::test_heartbeat test/test_coordinator.py::test_lookup_coordinator_failure
kafka/coordinator/base.py
kafka/coordinator/base.py