ajorgensen
ajorgensen

Reputation: 5151

Handling chunked request in Sinatra

In Sinatra I have a route setup similar to the following:

put '/test' do
  begin
    logger.info 'In put begin block'

    write_to_file(request.body.read)

    [200, '']
  rescue RuntimeError => e
    [500, 'some error']
  end
end

def write_to_file(data)
  logger.info "writing data with size #{data.size}"
  # Code to save file...
end

When I send data that is < ~500 MBytes it everything seems to work correctly but when I attempt to send data that is >= 500 MBytes I get some weird log output and then the client eventually errors out with the following error: Excon::Errors::SocketError: EOFError (EOFError)

The logs from the server (Sinatra) look like the following:

For data < 500 MBytes:

I, [2013-01-07T21:33:59.386768 #17380]  INFO -- : In put begin block
I, [2013-01-07T21:34:01.279922 #17380]  INFO -- : writing data with size 209715200
xxx.xxx.xxx.xxx - - [07/Jan/2013 21:34:22] "PUT /test " 200 - 22.7917

For data > 500 MBytes:

I, [2013-01-07T21:47:37.434022 #17386]  INFO -- : In put begin block
I, [2013-01-07T21:47:41.152932 #17386]  INFO -- : writing data with size 524288000
I, [2013-01-07T21:48:16.093683 #17380]  INFO -- : In put begin block
I, [2013-01-07T21:48:20.300391 #17380]  INFO -- : writing data with size 524288000
xxx.xxx.xxx.xxx - - [07/Jan/2013 21:48:39] "PUT /test " 200 - 62.4515
I, [2013-01-07T21:48:54.718971 #17386]  INFO -- : In put begin block
I, [2013-01-07T21:49:00.381725 #17386]  INFO -- : writing data with size 524288000
I, [2013-01-07T21:49:33.980043 #17267]  INFO -- : In put begin block
I, [2013-01-07T21:49:41.990671 #17267]  INFO -- : writing data with size 524288000
xxx.xxx.xxx.xxx - - [07/Jan/2013 21:50:06] "PUT /test " 200 - 110.2076
xxx.xxx.xxx.xxx - - [07/Jan/2013 21:51:22] "PUT /test " 200 - 108.5339

Not entirely sure whats going on here so I guess my question is two fold, A. What is fundamentally different between these two cases that would cause them to behave this way? B. Is there a better way to handle data to mitigate against this?

Upvotes: 1

Views: 420

Answers (1)

ajorgensen
ajorgensen

Reputation: 5151

The problem turned out to be with apache/passenger. Running the server with WEBrick alleviated the issue.

Upvotes: 1

Related Questions