adobe-apiplatform / api-gateway-request-tracking

Usage and Tracking Handler for the API Gateway
Other
4 stars 5 forks source link

cjson.decode should be wrapped in a pcall #9

Open ddragosd opened 8 years ago

ddragosd commented 8 years ago

This is where the error occurs.

val = cjson.decode(val_string)

It seems to be an edge case and we need to add a try/catch for this scenario. I’m assuming this is happening when a rule expires and we have an incoming request in that millisecond and the shared dictionary returns an empty string for a rule causing the cjson lib to complain ?... one possiblity

We should wrap the decode into a pcall as follows:

local ok, val = pcall(cjson.decode,val_string)
if not ok then
   -- continue
end
cristianconstantin commented 7 years ago

I've investigated and found that indeed the empty value is added to the cache in this line:

https://github.com/adobe-apiplatform/api-gateway-request-tracking/blob/55b9e120e7fc5b14bb556ed22c9c358accc01998/src/lua/api-gateway/tracking/RequestTrackingManager.lua#L93.

 dict:set(rule.id .. " " .. rule.format, "", 0.001, 0)

Wouldn't it be better to just remove the key from the shared dictionary?

ddragosd commented 7 years ago

👍 @cristianconstantin There's a delete api now.