dev@grizzly.java.net

About handling ReadHandler's error in processing multipart

From: Bongjae Chang <bongjae.chang_at_gmail.com>
Date: Wed, 12 Feb 2014 11:44:20 +0900

Hi,

When I tested multipart with http-multipart-samples sources, I met some
strange behavior.
I expected a failed notification of CompletionHandler if an error was
occurred in processing multipart, but there was no signal in some case.

As you know, a user should implement two interfaces in order to call
MultipartScanner.scan() successfully.
1. MultipartEntryHandler
2. ReadHandler in MultipartEntryHandler

If ReadHandler throws an exception in processing some works,
ReadHandler#onError() will be called. But user¹s CompletionHandler#failed()
was not called.

You can reproduce this with samples easily like this.

In UploaderHttpHandler.java

private void readAndSaveAvail() throws IOException {
    while(inputStream.isReady()) {
        final int readBytes = inputStream.read(buf);

        // limit max size for uploading a file.
        final long currentBytes = uploadedBytesCounter.addAndGet(readBytes);
        if (currentBytes >= 1024 * 1000) {
            // throw exception for stopping upload
            throw new IOException(³maximum size exceeded²);
        }
        ...
    }
}

I would like to know this behavior is intended.
(In other words, I would like to know if user should call
CompletionHandler#failed directly in ReadHandler#onError.)

Thanks!

Regards,
Bongjae Chang