Zero-length objects bug in Raw interface

Jonathan Lee jonathan_lee at comcast.com
Mon Jan 25 10:59:16 EST 2010


I found a small bug that occurs when writing zero-length objects to
the Raw interface. Usually, Riak closes the connection after a
successful write, but if the request's Content-Length = 0, it remains
open.  If you try to write another object using the same connection,
Riak ignores the request body.  The transactions below are an example.
 In the second session, notice that Riak did not allow me to send a
request body when PUTting to /raw/b/l.

The problem is actually inside webmachine, and the attached patch
solves this immediate problem.  However, I am concerned about
wrq:req_body/1. It seems like the function should return {Value,
ReqState}, not than just Value, and avoid maintaining state in the
process dictionary.  The current interface has problems if both
wrq:set_req_body and wrq:req_body are called by the same method or if
wrq:req_body is called with different RD values.  In both cases, the
state in the process dictionary clobbers the actual value.  Thoughts?

Thanks,
Jonathan

# --------------------
# Normal PUT:
# --------------------
$ telnet localhost 8098
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
PUT /raw/b/k HTTP/1.1
Host: 127.0.0.1:8098
Content-Type: application/octet-stream
Content-Length: 4

abcd
HTTP/1.1 204 No Content
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.5.2 (that tip is the fix)
Date: Fri, 22 Jan 2010 21:51:29 GMT
Content-Type: application/octet-stream
Content-Length: 0

Connection closed by foreign host.



# --------------------
# PUT zero-length object:
# --------------------
$ telnet localhost 8098
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
PUT /raw/b/k HTTP/1.1
Host: 127.0.0.1:8098
Content-Type: application/octet-stream
Content-Length: 0

HTTP/1.1 204 No Content
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.5.2 (that tip is the fix)
Date: Fri, 22 Jan 2010 21:55:47 GMT
Content-Type: application/octet-stream
Content-Length: 0

PUT /raw/b/l HTTP/1.1
Host: 127.0.0.1:8098
Content-Type: application/octet-stream
Content-Length: 4

HTTP/1.1 204 No Content
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.5.2 (that tip is the fix)
Date: Fri, 22 Jan 2010 21:56:08 GMT
Content-Type: text/plain
Content-Length: 0

Connection closed by foreign host.

#
# Riak did not allow me to supply the request body!
#

$ curl -i localhost:8098/raw/b/l
HTTP/1.1 200 OK
X-Riak-Vclock: a85hYGBgzGDKBVIsTI8C32YwJTLmsTL8mHXuCF8WAA==
Vary: Accept-Encoding
Server: MochiWeb/1.1 WebMachine/1.5.2 (that tip is the fix)
Link: </raw/b>; rel="up"
Last-Modified: Fri, 22 Jan 2010 21:56:08 GMT
ETag: 1WNUDpttTCtZ8ulOig9SEW
Date: Fri, 22 Jan 2010 21:56:27 GMT
Content-Type: application/octet-stream
Content-Length: 0
-------------- next part --------------
A non-text attachment was scrubbed...
Name: persistent_conn_req_bodies.patch
Type: application/octet-stream
Size: 2061 bytes
Desc: not available
URL: <http://lists.basho.com/pipermail/riak-users_lists.basho.com/attachments/20100125/2c884afa/attachment.patch>


More information about the riak-users mailing list