basho / riak_dt

Convergent replicated datatypes in Erlang
Apache License 2.0
353 stars 70 forks source link

Problems with counters in the HTTP API #108

Closed lucperkins closed 9 years ago

lucperkins commented 9 years ago

I've detected two problems in the HTTP API for counters.

Problem 1

You can pass in a raw integer as valid JSON. The following will work:

curl -XPOST http://localhost:10018/types/counters/buckets/test/datatypes/test \
  -H 'Content-Type: application/json' \
  -d 5

This will increment the counter by 5. Relatedly, passing in -5 will decrement the counter. Requiring that you specify JSON as the content type yet allowing you to pass in invalid JSON strikes me as a bug.

Problem 2

If you attempt to decrement by a negative integer, the operation will simply hang indefinitely. Here's an example:

curl -XPOST http://localhost:10018/types/counters/buckets/test/datatypes/test \
  -H 'Content-Type: application/json' \
  -d '{"decrement": -5}'

It seems to me that this should either result in a positive increment or throw an error.

lenary commented 9 years ago

Problem 2 seems like something that's reared its head again.

I think a while ago we made sure that decrements by negative numbers were undefined. decrements by positives, and increments by negatives and positives are defined. This may just be an error message not surfacing.

Frankly, the code related to JSON decoding is actually in riak_kv, but russell has omniscience over all of this anyway.

russelldb commented 9 years ago

This is all riak_kv, there is no API code in DT. The data type itself does not allow negative decrements. The error seems to be crashing riak's vnode. Please open against riak_kv