Reqwest: multipart form file upload sometimes fails

Created on 3 Feb 2018  路  3Comments  路  Source: seanmonstar/reqwest

Hello

I tried using reqwest to upload a file to a small golang webserver I am running inside a VM,
this mostly works but every 50-200 or so request fails.

The error I eventually see in the client is
thread panicked at 'calledResult::unwrap()on anErrvalue: Error { kind: Io(Custom { kind: WouldBlock, error: StringError("timed out") }), url: Some("http://10.10.30.63:28111/run") }', libcore/result.rs:945:5

and in the server:
multipart: NextPart: unexpected EOF

This is what i do with reqwest

fn stdout_from_vm_http(prober_com: &str) -> String {
    let client = reqwest::Client::new();

    let form = reqwest::multipart::Form::new()
        .file("com", prober_com).unwrap();

    let mut res = client.post("http://10.10.30.63:28111/run")
        .multipart(form)
        .send().unwrap();

    res.text().unwrap()
}

Where http://10.10.30.63:28111/run is provided by https://github.com/martinlindhe/supersafe

In order to verify that the issue is unrelated to the server code, I re-ran using curl, with no issues:

#!/bin/bash
for i in {0..65535}
do
   echo "iteration $i"
   curl -F "com=@/Users/m/dev/rs/dustbox-rs/utils/prober/prober.com" http://10.10.30.63:28111/run
done
bug

Most helpful comment

I have noticed before the multipart tests time out, I just assumed it was flakiness in Travis CI. To try to start debugging this, I'd look into the multipart file in this repo, and maybe add some trace! lines.

All 3 comments

I worked around this in my project by instead using curl-rust, using the following code

fn stdout_from_vm_http(prober_com: &str) -> String {
    use curl::easy::{Easy, Form};

    let mut dst = Vec::new();
    let mut easy = Easy::new();
    easy.url("http://10.10.30.63:28111/run").unwrap();

    let mut form = Form::new();
    form.part("com").file(prober_com).add();
    easy.httppost(form).unwrap();

    {
        let mut transfer = easy.transfer();
        transfer.write_function(|data| {
            dst.extend_from_slice(data);
            Ok(data.len())
        }).unwrap();
        transfer.perform().unwrap();
    }

    str::from_utf8(&dst).unwrap().to_owned()
}

I would like to assist in analysing this issue more, but I am a bit clueless of where to begin.

As posted above, I have a "mostly" reproducible scenario for this issue.

I'm off to elsewhere, but please ping me if I can be of any help

I have noticed before the multipart tests time out, I just assumed it was flakiness in Travis CI. To try to start debugging this, I'd look into the multipart file in this repo, and maybe add some trace! lines.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

hwchen picture hwchen  路  4Comments

samuela picture samuela  路  5Comments

theduke picture theduke  路  6Comments

silvioprog picture silvioprog  路  5Comments

jeprojects picture jeprojects  路  3Comments