diff --git a/kafka/coordinator/base.py b/kafka/coordinator/base.py
index e811e88..ab259dd 100644
--- a/kafka/coordinator/base.py
+++ b/kafka/coordinator/base.py
@@ -245,13 +245,12 @@ class BaseCoordinator(object):
             # ensure that there are no pending requests to the coordinator.
             # This is important in particular to avoid resending a pending
             # JoinGroup request.
-            if self._client.in_flight_request_count(self.coordinator_id):
-                while not self.coordinator_unknown():
-                    self._client.poll(delayed_tasks=False)
-                    if not self._client.in_flight_request_count(self.coordinator_id):
-                        break
-                else:
-                    continue
+            while not self.coordinator_unknown():
+                if not self._client.in_flight_request_count(self.coordinator_id):
+                    break
+                self._client.poll(delayed_tasks=False)
+            else:
+                continue
 
             future = self._send_join_group_request()
             self._client.poll(future=future)
@@ -287,6 +286,10 @@ class BaseCoordinator(object):
             e = Errors.GroupCoordinatorNotAvailableError(self.coordinator_id)
             return Future().failure(e)
 
+        elif not self._client.ready(self.coordinator_id, metadata_priority=False):
+            e = Errors.NodeNotReadyError(self.coordinator_id)
+            return Future().failure(e)
+
         # send a join group request to the coordinator
         log.info("(Re-)joining group %s", self.group_id)
         request = JoinGroupRequest[0](
@@ -417,6 +420,13 @@ class BaseCoordinator(object):
         if self.coordinator_unknown():
             e = Errors.GroupCoordinatorNotAvailableError(self.coordinator_id)
             return Future().failure(e)
+
+        # We assume that coordinator is ready if we're sending SyncGroup
+        # as it typically follows a successful JoinGroup
+        # Also note that if client.ready() enforces a metadata priority policy,
+        # we can get into an infinite loop if the leader assignment process
+        # itself requests a metadata update
+
         future = Future()
         _f = self._client.send(self.coordinator_id, request)
         _f.add_callback(self._handle_sync_group_response, future, time.time())
@@ -468,6 +478,10 @@ class BaseCoordinator(object):
         if node_id is None:
             return Future().failure(Errors.NoBrokersAvailable())
 
+        elif not self._client.ready(node_id, metadata_priority=False):
+            e = Errors.NodeNotReadyError(node_id)
+            return Future().failure(e)
+
         log.debug("Sending group coordinator request for group %s to broker %s",
                   self.group_id, node_id)
         request = GroupCoordinatorRequest[0](self.group_id)
@@ -554,6 +568,14 @@ class BaseCoordinator(object):
 
     def _send_heartbeat_request(self):
         """Send a heartbeat request"""
+        if self.coordinator_unknown():
+            e = Errors.GroupCoordinatorNotAvailableError(self.coordinator_id)
+            return Future().failure(e)
+
+        elif not self._client.ready(self.coordinator_id, metadata_priority=False):
+            e = Errors.NodeNotReadyError(self.coordinator_id)
+            return Future().failure(e)
+
         request = HeartbeatRequest[0](self.group_id, self.generation, self.member_id)
         log.debug("Heartbeat: %s[%s] %s", request.group, request.generation_id, request.member_id)  # pylint: disable-msg=no-member
         future = Future()
diff --git a/kafka/protocol/struct.py b/kafka/protocol/struct.py
index 4c1afcb..3288172 100644
--- a/kafka/protocol/struct.py
+++ b/kafka/protocol/struct.py
@@ -18,7 +18,12 @@ class Struct(AbstractType):
         elif len(args) > 0:
             raise ValueError('Args must be empty or mirror schema')
         else:
-            self.__dict__.update(kwargs)
+            for name in self.SCHEMA.names:
+                self.__dict__[name] = kwargs.pop(name, None)
+            if kwargs:
+                raise ValueError('Keyword(s) not in schema %s: %s'
+                                 % (list(self.SCHEMA.names),
+                                    ', '.join(kwargs.keys())))
 
         # overloading encode() to support both class and instance
         # Without WeakMethod() this creates circular ref, which

KeyError: 'error_code' at kafka/protocol/struct.py __repr__
kafka-python==1.3.1, kafka 0.10.1.0
I've set consumer's session_timeout_ms bigger than group.max.session.timeout.ms in the broker and used group coordination. Here is my consumer setup:
```python
SECOND = 1000
consumer = kafka.KafkaConsumer(
    topic,
    bootstrap_servers = bootstrap_servers,
    client_id = client_id,
    group_id = group_id,
    value_deserializer = value_deserializer,
    auto_offset_reset = 'earliest',
    enable_auto_commit = False,
    consumer_timeout_ms = 1000 * 1,
    api_version = (0, 10),
    session_timeout_ms = SECOND * 60 * 20,
    heartbeat_interval_ms = SECOND,
)
```
I use celery and I got the following exception:
```
[2016-12-12 07:50:36,281: ERROR/Worker-2] Attempt to join group some_name failed due to fatal error: [Error 26] InvalidSessionTimeoutError: JoinGroupResponse_v0(error_code=26, generation_id=0, group_protocol=u'', leader_id=u'', member_id=u'', members=[])
[2016-12-12 07:50:36,464: INFO/MainProcess] Task task_name[task_id] succeeded in 0.72630248405s: None
Traceback (most recent call last):
  File "/usr/lib/python2.7/logging/__init__.py", line 851, in emit
    msg = self.format(record)
  File "/usr/lib/python2.7/logging/__init__.py", line 724, in format
    return fmt.format(record)
  File "/home/qwe/venv/local/lib/python2.7/site-packages/celery/utils/log.py", line 142, in format
    msg = logging.Formatter.format(self, record)
  File "/usr/lib/python2.7/logging/__init__.py", line 464, in format
    record.message = record.getMessage()
  File "/usr/lib/python2.7/logging/__init__.py", line 328, in getMessage
    msg = msg % self.args
  File "/home/qwe/venv/local/lib/python2.7/site-packages/kafka/protocol/struct.py", line 46, in __repr__
    key_vals.append('%s=%s' % (name, field.repr(self.__dict__[name])))
KeyError: 'error_code'
```
diff --git a/test/test_protocol.py b/test/test_protocol.py
index 1c9f0f9..aa3dd17 100644
--- a/test/test_protocol.py
+++ b/test/test_protocol.py
@@ -7,8 +7,9 @@ import six
 
 from kafka.protocol.api import RequestHeader
 from kafka.protocol.commit import GroupCoordinatorRequest
-from kafka.protocol.fetch import FetchResponse
+from kafka.protocol.fetch import FetchRequest, FetchResponse
 from kafka.protocol.message import Message, MessageSet, PartialMessage
+from kafka.protocol.metadata import MetadataRequest
 from kafka.protocol.types import Int16, Int32, Int64, String
 
 
@@ -244,3 +245,16 @@ def test_decode_fetch_response_partial():
     m1 = partitions[0][3]
     assert len(m1) == 2
     assert m1[1] == (None, None, PartialMessage())
+
+
+def test_struct_unrecognized_kwargs():
+    try:
+        mr = MetadataRequest[0](topicz='foo')
+        assert False, 'Structs should not allow unrecognized kwargs'
+    except ValueError:
+        pass
+
+
+def test_struct_missing_kwargs():
+    fr = FetchRequest[0](max_wait_time=100)
+    assert fr.min_bytes is None

pip install -e .[dev]
parse_log_pytest
requirements.txt
pytest pytest-cov pytest-catchlog pytest-pylint pytest-sugar pytest-mock mock python-snappy lz4tools xxhash pytest
apt-get update apt-get install -y gcc 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
astroid==2.11.7
attrs==22.2.0
Babel==2.11.0
certifi==2021.5.30
charset-normalizer==2.0.12
coverage==6.2
cramjam==2.5.0
dill==0.3.4
docutils==0.18.1
idna==3.10
imagesize==1.4.1
importlib-metadata==4.8.3
iniconfig==1.1.1
isort==5.10.1
Jinja2==3.0.3
-e git+https://github.com/dpkp/kafka-python.git@218a9014b749e52a2b8d40da6e3443c8132b8fa1#egg=kafka_python
lazy-object-proxy==1.7.1
lz4tools==1.3.1.2
MarkupSafe==2.0.1
mccabe==0.7.0
mock==5.2.0
packaging==21.3
platformdirs==2.4.0
pluggy==1.0.0
pockets==0.9.1
py==1.11.0
Pygments==2.14.0
pylint==2.13.9
pyparsing==3.1.4
pytest==7.0.1
pytest-catchlog==1.2.2
pytest-cov==4.0.0
pytest-mock==3.6.1
pytest-pylint==0.18.0
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
toml==0.10.2
tomli==1.2.3
typed-ast==1.5.5
typing_extensions==4.1.1
urllib3==1.26.20
wrapt==1.16.0
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
      - astroid==2.11.7
      - attrs==22.2.0
      - babel==2.11.0
      - charset-normalizer==2.0.12
      - coverage==6.2
      - cramjam==2.5.0
      - dill==0.3.4
      - docutils==0.18.1
      - idna==3.10
      - imagesize==1.4.1
      - importlib-metadata==4.8.3
      - iniconfig==1.1.1
      - isort==5.10.1
      - jinja2==3.0.3
      - lazy-object-proxy==1.7.1
      - lz4tools==1.3.1.2
      - markupsafe==2.0.1
      - mccabe==0.7.0
      - mock==5.2.0
      - packaging==21.3
      - platformdirs==2.4.0
      - pluggy==1.0.0
      - pockets==0.9.1
      - py==1.11.0
      - pygments==2.14.0
      - pylint==2.13.9
      - pyparsing==3.1.4
      - pytest==7.0.1
      - pytest-catchlog==1.2.2
      - pytest-cov==4.0.0
      - pytest-mock==3.6.1
      - pytest-pylint==0.18.0
      - 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
      - toml==0.10.2
      - tomli==1.2.3
      - typed-ast==1.5.5
      - typing-extensions==4.1.1
      - urllib3==1.26.20
      - wrapt==1.16.0
      - xxhash==3.2.0
      - zipp==3.6.0
prefix: /opt/conda/envs/kafka-python

test/test_protocol.py::test_struct_unrecognized_kwargs test/test_protocol.py::test_struct_missing_kwargs
test/test_protocol.py::test_create_message test/test_protocol.py::test_encode_message_v0 test/test_protocol.py::test_encode_message_v1 test/test_protocol.py::test_decode_message test/test_protocol.py::test_encode_message_set test/test_protocol.py::test_decode_message_set test/test_protocol.py::test_encode_message_header test/test_protocol.py::test_decode_message_set_partial test/test_protocol.py::test_decode_fetch_response_partial
kafka/protocol/struct.py kafka/coordinator/base.py
kafka/protocol/struct.py kafka/coordinator/base.py