basho/riak_cs — pull request #593 by reiddraper (2013-06-14 21:27:43+00:00)
Title: Fix GET FSM race conditions

* Fix two bugs in the GET FSM
- introduced in b14d86d9a5ca8ed7bddb40ed0e82d13b63d925af
* Fix one bug in the accompanying test
- introduced in fec985e156fc308f40c682e9fc88ab3aec423575

The previous code would mistakenly stop the GET FSM when the
`blocks_intransit` queue was empty. Small values of the get buffer would
cause this to happen even more often. The GET FSM should only stop once
all blocks have been sent. This change introduces a new record field
called `num_sent` to keep track of the number of blocks returned to the
caller. We now also keep track of the `From' param if we aren't able to
send any bytes back to the user in case of a `get_next_chunk` call.

The eunit test had a bug where it would expect Content-Length (10000
hardcoded) chunks from the GET FSM, instead of:

Content-Length / BlockSize

This was masked by the fact that one the `foldl` got a done message, it
would happily loop a few extra times. And since Content-Length was
always larger than the number of blocks, we never say anything.