Skip to content

FileUploadHandler cannot process concurrent upload request #5

@eblosug

Description

@eblosug

How to reproduce this issue:

Run a small test server

import io.netty.handler.codec.http.HttpMethod;
import org.restexpress.Request;
import org.restexpress.Response;
import org.restexpress.RestExpress;
import java.nio.file.Files;

public class TestUploadServer {
    public static void main(String[] args) throws Throwable {
        RestExpress server = new RestExpress().setSupportFileUpload(true);
        server.uri("/upload", new MyController()).action("upload", HttpMethod.POST);
        server.bind(8901);
        server.awaitShutdown();
    }

    static class MyController {
        public String upload(Request request, Response response) throws Exception{
            byte[] data = Files.readAllBytes(request.getUploadedFileAttachment().toPath());
            return "YOU SENT:\n" + new String(data);
        }
    }
}

Create two files to upload:

python3 -c 'print("a"*8000)' > a.txt
python3 -c 'print("b"*8000)' > b.txt

Start the first upload:

curl -v -F upload=@a.txt --limit-rate 1k http://127.0.0.1:8901/upload

After 3 seconds, start the second upload in another terminal:

curl -v -F upload=@b.txt --limit-rate 1k http://127.0.0.1:8901/upload

The first request will not get a response because the controller throws a NoSuchFileException.

The second request will get a response that has a mix of a and bs in the body.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions