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

cjson.decode should be wrapped in a pcall #9

Open
ddragosd opened this issue Aug 29, 2016 · 2 comments
Open

cjson.decode should be wrapped in a pcall #9

ddragosd opened this issue Aug 29, 2016 · 2 comments
Assignees

Comments

@ddragosd
Copy link
Member

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
ddragosd added a commit that referenced this issue Aug 29, 2016
@ddragosd ddragosd self-assigned this Aug 29, 2016
selfxp pushed a commit that referenced this issue Sep 7, 2016
* Added a test to prove #9

* added a try/catch to cjson.decode
@cristianconstantin
Copy link
Contributor

cristianconstantin commented Oct 25, 2016

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

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

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

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

@ddragosd
Copy link
Member Author

👍 @cristianconstantin
There's a delete api now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants