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 in case of connection timeout #272

Merged
merged 3 commits into from
Feb 14, 2018
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
8 changes: 2 additions & 6 deletions lib/kafka_ex/server.ex
Original file line number Diff line number Diff line change
Expand Up @@ -486,12 +486,8 @@ defmodule KafkaEx.Server do
|> client_request(updated_state)
|> module.create_request

response = broker
|> NetworkClient.send_sync_request(
wire_request,
config_sync_timeout()
)
|> module.parse_response
response = NetworkClient.send_sync_request(broker, wire_request, 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 99).

response = if response != nil, do: module.parse_response(response), else: nil

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 89).


state_out = State.increment_correlation_id(updated_state)

Expand Down
45 changes: 13 additions & 32 deletions lib/kafka_ex/server_0_p_8_p_2.ex
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,8 @@ defmodule KafkaEx.Server0P8P2 do
Logger.log(:error, "Coordinator for topic #{offset_fetch.topic} is not available")
{:topic_not_found, state}
_ ->
response = broker
|> NetworkClient.send_sync_request(offset_fetch_request, config_sync_timeout())
|> OffsetFetch.parse_response
response = NetworkClient.send_sync_request(broker, offset_fetch_request, 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 103).

response = if response != nil, do: OffsetFetch.parse_response(response), else: nil

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 90).

{response, %{state | correlation_id: state.correlation_id + 1}}
end

Expand Down Expand Up @@ -155,40 +154,22 @@ defmodule KafkaEx.Server0P8P2 do
end
end

defp fetch(fetch_request, state) do
true = consumer_group_if_auto_commit?(fetch_request.auto_commit, state)
fetch_data = Fetch.create_request(%FetchRequest{
fetch_request |
client_id: @client_id,
correlation_id: state.correlation_id,
})
{broker, state} = case MetadataResponse.broker_for_topic(state.metadata, state.brokers, fetch_request.topic, fetch_request.partition) do
nil ->
updated_state = update_metadata(state)
{MetadataResponse.broker_for_topic(updated_state.metadata, updated_state.brokers, fetch_request.topic, fetch_request.partition), updated_state}
broker -> {broker, state}
end

case broker do
nil ->
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}
defp fetch(request, state) do
true = consumer_group_if_auto_commit?(request.auto_commit, state)
case network_request(request, Fetch, state) do
{{:error, error}, state_out} -> {error, state_out}
{response, state_out} ->
last_offset = response |> hd |> Map.get(:partitions) |> hd |> Map.get(:last_offset)
if last_offset != nil && fetch_request.auto_commit do
if last_offset != nil && request.auto_commit do
offset_commit_request = %OffsetCommit.Request{
topic: fetch_request.topic,
topic: request.topic,
offset: last_offset,
partition: fetch_request.partition,
consumer_group: state.consumer_group}
{_, state} = offset_commit(state, offset_commit_request)
partition: request.partition,
consumer_group: state_out.consumer_group}
{_, state} = offset_commit(state_out, offset_commit_request)
{response, state}
else
{response, state}
{response, state_out}
end
end
end
Expand Down