Cordova Android app using SSL multipart / form-data transmission raises Rack app error: # <EOFError: bad content body>
We have a Cordova application that connects to the rails server via SSL. It seems that our recent change from Unicorn to Puma caused a problem when the Android application gets 500 errors when sending the image file to the server.
Some notes:
- An iOS application version built using the same code works fine
- Everything works fine if not using SSL
- All other requests are SSL and work fine, only when sending multipart / form-data, that the problem causes its ugly head.
I try to think about what might be the problem, or even where to look for a solution. I am new to Puma, so I don’t know if my configuration is missing something important to solve this problem. Any ideas would be greatly appreciated.
IOS request (works great)
POST /api/v2/attachments HTTP/1.1
Host: <omitted for security>
Accept: */*
Proxy-Connection: keep-alive
X-Requested-With: XMLHttpRequest
Accept-Encoding: gzip, deflate
If-None-Match: "2146f2b315668b29682ec01973ae4155"
Accept-Language: en-us
Content-Type: multipart/form-data; boundary=+++++org.apache.cordova.formBoundary
Content-Length: 13794
User-Agent: Mozilla/5.0 (iPhone; CPU iPhone OS 9_1 like Mac OS X) AppleWebKit/601.1.46 (KHTML, like Gecko) Mobile/13B143 (4954749952)
Connection: keep-alive
Cookie: XSRF-TOKEN=<omitted for security>; _session_id=<omitted for security>
--+++++org.apache.cordova.formBoundary
Content-Disposition: form-data; name="type"
Image
--+++++org.apache.cordova.formBoundary
Content-Disposition: form-data; name="attachment[attachment]"; filename="cdv_photo_003.jpg"
Content-Type: image/jpeg
Content-Length: 13466
iُ B~,"
#BR$3br
%&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
B #3Rbr
$4%&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz
""""""''''',,,,,,,,,,
...................................................(<a$GW_Uպi&dA+x=R
?)uHv"ԊdcpIސW̚<<Kx~E1xEN]M%>r{Y_Yc<jʥYH_2r[P['6 d#wS+5Bfu
<more Binary data omitted for brevity>
--+++++org.apache.cordova.formBoundary--
Equivalent Android request (causes an error)
POST /api/v2/attachments HTTP/1.1
Content-Type: multipart/form-data; boundary=+++++
Cookie: _session_id=<omitted for security>; XSRF-TOKEN=<omitted for security>
Transfer-Encoding: chunked
User-Agent: Dalvik/2.1.0 (Linux; U; Android 5.0; SM-G900F Build/LRX21T)
Host: <omitted for security>
Connection: Keep-Alive
Accept-Encoding: gzip
--+++++
Content-Disposition: form-data; name="type"
Image
--+++++
Content-Disposition: form-data; name="attachment[attachment]"; filename="modified.jpg?1446611766814"
Content-Type: image/jpeg
Exif
(1#%(:3=<9387@H\N@DWE78PmQW_bghg>Mqypdx\egc"
#BR$3br
<more Binary data omitted for brevity>
--+++++--
There are some obvious differences in these requests, and although I would not call myself an HTTP expert, none of the differences seem to me like something that could cause Puma to crash.
Rack Error Trace:
2015-11-04T04:36:07.041124+00:00 app[web.1]: 2015-11-04 04:36:07 +0000: Rack app error: #<EOFError: bad content body>
2015-11-04T04:36:07.041131+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:74:in `block in fast_forward_to_first_boundary'
2015-11-04T04:36:07.041133+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:72:in `loop'
2015-11-04T04:36:07.041134+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:72:in `fast_forward_to_first_boundary'
2015-11-04T04:36:07.041152+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/multipart/parser.rb:15:in `parse'
2015-11-04T04:36:07.041153+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/multipart.rb:25:in `parse_multipart'
2015-11-04T04:36:07.041154+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/request.rb:377:in `parse_multipart'
2015-11-04T04:36:07.041154+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/request.rb:203:in `POST'
2015-11-04T04:36:07.041155+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:26:in `method_override'
2015-11-04T04:36:07.041156+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/methodoverride.rb:14:in `call'
2015-11-04T04:36:07.041157+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041157+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/runtime.rb:17:in `call'
2015-11-04T04:36:07.041158+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041158+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-rewrite-1.5.0/lib/rack/rewrite.rb:24:in `call'
2015-11-04T04:36:07.041159+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041159+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/activesupport-4.0.5/lib/active_support/cache/strategy/local_cache.rb:83:in `call'
2015-11-04T04:36:07.041160+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041160+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/actionpack-4.0.5/lib/action_dispatch/middleware/static.rb:64:in `call'
2015-11-04T04:36:07.041161+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041161+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/rack-1.5.2/lib/rack/sendfile.rb:112:in `call'
2015-11-04T04:36:07.041161+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041162+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.5/lib/rails/engine.rb:511:in `call'
2015-11-04T04:36:07.041162+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.5/lib/rails/application.rb:97:in `call'
2015-11-04T04:36:07.041163+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/railties-4.0.5/lib/rails/railtie/configurable.rb:30:in `method_missing'
2015-11-04T04:36:07.041163+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/newrelic_rpm-3.13.2.302/lib/new_relic/agent/instrumentation/middleware_tracing.rb:67:in `call'
2015-11-04T04:36:07.041163+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/configuration.rb:78:in `call'
2015-11-04T04:36:07.041164+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/server.rb:541:in `handle_request'
2015-11-04T04:36:07.041164+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/server.rb:388:in `process_client'
2015-11-04T04:36:07.041165+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/server.rb:270:in `block in run'
2015-11-04T04:36:07.041165+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/thread_pool.rb:106:in `call'
2015-11-04T04:36:07.041165+00:00 app[web.1]: /app/vendor/bundle/ruby/2.1.0/gems/puma-2.14.0/lib/puma/thread_pool.rb:106:in `block in spawn_thread'
2015-11-04T04:36:07.523877+00:00 heroku[router]: sock=backend at=error code=H18 desc="Server Request Interrupted" method=POST path="/api/v2/attachments" host=<omitted for security> request_id=a5958dab-8c7c-4121-acc3-54d28be9ad4c fwd="<omitted for security>" dyno=web.1 connect=2ms service=484ms status=503 bytes=154
, , , Puma / . , , "" , .
, , Content-Length, , - , HTTP , chunked- .
( ), SSL Content-Length, , chunked- .
, cordova. cordova-file-transfer-plugin, chunked false.
, . https://github.com/apache/cordova-plugin-file-transfer
options.chunkedMode = false;