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 #107

Closed lucperkins closed 9 years ago

lucperkins commented 9 years ago

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

  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.

  1. 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.

lucperkins commented 9 years ago

Whoops. Duplicate. My bad.