-1 (non-binding)

I found a breaking bug in the new HTTP API. The messages do not conform to the 
HTTP standard for chunked transfer encoding. in RFC 2616 Sec. 3 
(http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html 
<http://www.w3.org/Protocols/rfc2616/rfc2616-sec3.html>) a chunk is defined as:

chunk = chunk-size [ chunk-extension ] CRLF
        chunk-data CRLF

The HTTP API currently sends a chunk as:

chunk = chunk-size LF
        chunk-data

A standard conform HTTP client like curl can’t correctly interpret the data as 
a complete chunk. In curl it currently looks like this:

104
{"subscribed":{"framework_id":{"value":"20150820-114552-16777343-5050-43704-0000"}},"type":"SUBSCRIBED"}20
{"type":"HEARTBEAT”}666
…. waiting …
{"offers":{"offers":[{"agent_id":{"value":"20150820-114552-16777343-5050-43704-S0"},"framework_id":{"value":"20150820-114552-16777343-5050-43704-0000"},"hostname":"localhost","id":{"value":"20150820-114552-16777343-5050-43704-O0"},"resources":[{"name":"cpus","role":"*","scalar":{"value":8},"type":"SCALAR"},{"name":"mem","role":"*","scalar":{"value":15360},"type":"SCALAR"},{"name":"disk","role":"*","scalar":{"value":2965448},"type":"SCALAR"},{"name":"ports","ranges":{"range":[{"begin":31000,"end":32000}]},"role":"*","type":"RANGES"}],"url":{"address":{"hostname":"localhost","ip":"127.0.0.1","port":5051},"path":"\/slave(1)","scheme":"http"}}]},"type":"OFFERS”}20
… waiting …
{"type":"HEARTBEAT”}20
… waiting …

It will receive a couple of messages after successful registration with the 
master and the last thing printed is a number (in this case 666). Then after 
some time it will print the first offers message followed by the number 20. The 
explanation for this behavior is, that curl can’t interpret the data it gets 
from Mesos as a complete chunk and waits for the missing data. So it prints 
what it thinks is a chunk (a message followed by the size of the next messsage) 
and keeps the rest of the message until another message arrives and so on. The 
fix for this is to terminate both lines, the message size and the message data, 
with CRLF.

Cheers,
Dario

Reply via email to