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

Avoid parsing nil response when connection timeout occured #235

Closed
Closed
Show file tree
Hide file tree
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
11 changes: 7 additions & 4 deletions lib/kafka_ex/server_0_p_8_p_0.ex
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,13 @@ defmodule KafkaEx.Server0P8P0 do
Logger.log(:error, "Leader for topic #{fetch_request.topic} is not available")
{:topic_not_found, state}
_ ->
response = broker
|> NetworkClient.send_sync_request(fetch_data, config_sync_timeout())
|> Fetch.parse_response
{response, %{state | correlation_id: state.correlation_id + 1}}
response = NetworkClient.send_sync_request(broker, fetch_data, config_sync_timeout())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long (max is 80, was 93).

case response do
nil -> {response, state}
_ ->
response = Fetch.parse_response(response)
{response, %{state | correlation_id: state.correlation_id + 1}}
end
end
end
end
33 changes: 18 additions & 15 deletions lib/kafka_ex/server_0_p_8_p_2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,24 @@ defmodule KafkaEx.Server0P8P2 do
Logger.log(:error, "Leader for topic #{fetch_request.topic} is not available")
{:topic_not_found, state}
_ ->
response = broker
|> NetworkClient.send_sync_request(fetch_data, config_sync_timeout())
|> Fetch.parse_response
state = %{state | correlation_id: state.correlation_id + 1}
last_offset = response |> hd |> Map.get(:partitions) |> hd |> Map.get(:last_offset)
if last_offset != nil && fetch_request.auto_commit do
offset_commit_request = %OffsetCommit.Request{
topic: fetch_request.topic,
offset: last_offset,
partition: fetch_request.partition,
consumer_group: state.consumer_group}
{_, state} = offset_commit(state, offset_commit_request)
{response, state}
else
{response, state}
response = NetworkClient.send_sync_request(broker, fetch_data, config_sync_timeout())

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long (max is 80, was 93).

case response do
nil -> {response, state}
_ ->
response = Fetch.parse_response(response)
state = %{state | correlation_id: state.correlation_id + 1}
last_offset = response |> hd |> Map.get(:partitions) |> hd |> Map.get(:last_offset)

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Line is too long (max is 80, was 95).

if last_offset != nil && fetch_request.auto_commit do

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Function body is nested too deep (max depth is 2, was 3).

offset_commit_request = %OffsetCommit.Request{
topic: fetch_request.topic,
offset: last_offset,
partition: fetch_request.partition,
consumer_group: state.consumer_group}
{_, state} = offset_commit(state, offset_commit_request)
{response, state}
else
{response, state}
end
end
end
end
Expand Down