From a735406363ae581dce2187f018390737413bfb5c Mon Sep 17 00:00:00 2001 From: sko00o Date: Sat, 7 May 2022 14:18:31 +0800 Subject: [PATCH 1/4] handle unknown errcode --- lib/resty/kafka/producer.lua | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/resty/kafka/producer.lua b/lib/resty/kafka/producer.lua index 177a832d..e2d3915d 100644 --- a/lib/resty/kafka/producer.lua +++ b/lib/resty/kafka/producer.lua @@ -168,15 +168,15 @@ local function _send(self, broker_conf, topic_partitions) sendbuffer:offset(topic, partition_id, r.offset) sendbuffer:clear(topic, partition_id) else - err = Errors[errcode] + err = Errors[errcode] or Errors[-1] -- set retries according to the error list local retryable0 = retryable or err.retriable local index = sendbuffer:err(topic, partition_id, err.msg, retryable0) - ngx_log(INFO, "retry to send messages to kafka err: ", err.msg, ", retryable: ", retryable0, - ", topic: ", topic, ", partition_id: ", partition_id, ", length: ", index / 2) + ngx_log(INFO, "retry to send messages to kafka err: ", err.msg, "(", errcode, "), retryable: ", + retryable0, ", topic: ", topic, ", partition_id: ", partition_id, ", length: ", index / 2) end end end From 6b744eee2b08aac31ad337c022719c2f54a7d339 Mon Sep 17 00:00:00 2001 From: sko00o Date: Mon, 9 May 2022 10:36:39 +0800 Subject: [PATCH 2/4] fix: handle errcode in basic-consumer --- lib/resty/kafka/basic-consumer.lua | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/resty/kafka/basic-consumer.lua b/lib/resty/kafka/basic-consumer.lua index fd16f97e..25e0d9b2 100644 --- a/lib/resty/kafka/basic-consumer.lua +++ b/lib/resty/kafka/basic-consumer.lua @@ -76,12 +76,12 @@ function _M.list_offset(self, topic, partition, timestamp) local errcode = data.errcode if errcode ~= 0 then - err = Errors[errcode].msg + err = Errors[errcode] or Errors[-1] - ngx_log(INFO, "list offset err: ", err, ", topic: ", topic, + ngx_log(INFO, "list offset err: ", err.msg, "(", errcode, "), topic: ", topic, ", partition_id: ", partition) - return nil, err + return nil, err.msg end return data.offset, nil @@ -136,12 +136,12 @@ function _M.fetch(self, topic, partition, offset) local errcode = data.errcode if errcode ~= 0 then - err = Errors[errcode].msg + err = Errors[errcode] or Errors[-1] - ngx_log(INFO, "fetch message err: ", err, ", topic: ", topic, + ngx_log(INFO, "fetch message err: ", err.msg, "(", errcode, "), topic: ", topic, ", partition_id: ", partition) - return nil, err + return nil, err.msg end return data, nil From e9638eb0fbbeb841817f2b679b1a9782c634c2a6 Mon Sep 17 00:00:00 2001 From: sko00o Date: Mon, 9 May 2022 10:46:42 +0800 Subject: [PATCH 3/4] fix: handle unknown errcode in client also fix errcode not used --- lib/resty/kafka/client.lua | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/resty/kafka/client.lua b/lib/resty/kafka/client.lua index e4050fa5..f92a91b6 100644 --- a/lib/resty/kafka/client.lua +++ b/lib/resty/kafka/client.lua @@ -144,7 +144,8 @@ local function _fetch_api_versions(broker, client_id) local errcode, api_versions = api_versions_decode(resp) if errcode ~= 0 then - return nil, Errors[err] + err = Errors[errcode] or Errors[-1] + return nil, err.msg else return api_versions, nil end From fbfa16d8bafef8c18f5045bd25c5e2797c587f4a Mon Sep 17 00:00:00 2001 From: "Wenyu.Li" Date: Mon, 9 May 2022 11:12:30 +0800 Subject: [PATCH 4/4] fix local variable Co-authored-by: doujiang --- lib/resty/kafka/client.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/resty/kafka/client.lua b/lib/resty/kafka/client.lua index f92a91b6..55f34cca 100644 --- a/lib/resty/kafka/client.lua +++ b/lib/resty/kafka/client.lua @@ -144,7 +144,7 @@ local function _fetch_api_versions(broker, client_id) local errcode, api_versions = api_versions_decode(resp) if errcode ~= 0 then - err = Errors[errcode] or Errors[-1] + local err = Errors[errcode] or Errors[-1] return nil, err.msg else return api_versions, nil