Skip to content

Reset conn configs on exception in conn.check_version() #1977

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

Merged
merged 1 commit into from
Dec 29, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions kafka/conn.py
Original file line number Diff line number Diff line change
Expand Up @@ -1151,6 +1151,10 @@ def check_version(self, timeout=2, strict=False, topics=[]):
stashed[key] = self.config[key]
self.config[key] = override_config[key]

def reset_override_configs():
for key in stashed:
self.config[key] = stashed[key]

# kafka kills the connection when it doesn't recognize an API request
# so we can send a test request and then follow immediately with a
# vanilla MetadataRequest. If the server did not recognize the first
Expand All @@ -1170,6 +1174,7 @@ def check_version(self, timeout=2, strict=False, topics=[]):

for version, request in test_cases:
if not self.connect_blocking(timeout_at - time.time()):
reset_override_configs()
raise Errors.NodeNotReadyError()
f = self.send(request)
# HACK: sleeping to wait for socket to send bytes
Expand Down Expand Up @@ -1226,10 +1231,10 @@ def check_version(self, timeout=2, strict=False, topics=[]):
log.info("Broker is not v%s -- it did not recognize %s",
version, request.__class__.__name__)
else:
reset_override_configs()
raise Errors.UnrecognizedBrokerVersion()

for key in stashed:
self.config[key] = stashed[key]
reset_override_configs()
return version

def __str__(self):
Expand Down