commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Keith Kowalczykowski (JIRA)" <>
Subject [jira] Created: (FILEUPLOAD-136) FileUpload race condition with used with Jetty 6
Date Tue, 12 Jun 2007 04:24:26 GMT
FileUpload race condition with used with Jetty 6

                 Key: FILEUPLOAD-136
             Project: Commons FileUpload
          Issue Type: Bug
    Affects Versions: 1.2
         Environment: Running on Windows XP SP2 with Jetty 6 embedded and Firefox
            Reporter: Keith Kowalczykowski
            Priority: Critical

When running commons file upload with Jetty 6, ServletFileUpload.parseRequest spins and never
returns when the user clicks the "stop" button in their browser while an upload is in progress.

Reproduction Steps:
 * Create a simple servlet / html form which accepts a file upload using commons file upload
(or use the example code below).
 * Upload a sufficiently large file that you have time to click the stop button before the
upload completes.
 * Observe that the thread is now stuck within file upload.

Other Information:

Using jstack, I was able to get the following trace of where it is blocking. It looks like
it is on a read() call that file upload is making.

    at org/mortbay/jetty/HttpParser$Input.blockForContent(
    at org/mortbay/jetty/HttpParser$
    at org/apache/commons/fileupload/MultipartStream$ItemInputStream.makeAvailable(
    at org/apache/commons/fileupload/MultipartStream$ItemInputStream.close(
    at org/apache/commons/fileupload/util/Streams.copy(
    at org/apache/commons/fileupload/util/Streams.copy(
    at org/apache/commons/fileupload/FileUploadBase.parseRequest(
    at org/apache/commons/fileupload/servlet/ServletFileUpload.parseRequest(
    at test/Main$1.handle(
    at org/mortbay/jetty/handler/HandlerWrapper.handle(
    at org/mortbay/jetty/Server.handle(
    at org/mortbay/jetty/HttpConnection.handleRequest(
    at org/mortbay/jetty/HttpConnection$RequestHandler.content(
    at org/mortbay/jetty/HttpParser.parseNext(
    at org/mortbay/jetty/HttpParser.parseAvailable(
    at org/mortbay/jetty/HttpConnection.handle(
    at org/mortbay/jetty/bio/SocketConnector$
    at org/mortbay/thread/BoundedThreadPool$
    at jrockit/vm/RNI.c2java(IIII)V(Native Method)
    -- end of trac

Originally I thought this was an issue with our code, however, I have since isolated it to
a simple test case. Bellow is a class file called Main which when run will instantiate an
instance of Jetty on port 8080 and an HTML document that will post a file upload to the servlet.
When the stop button is pressed, you will see that the line "Starting processing" is printed,
but neither the "Exception occured in processing" or "Processing completed" are printed. I
have a full eclipse project (jars and all) on my machine that I was planning on uploading
with this ticket, however, I don't see a way to attach a file. Therefore, I have copied and
pasted the two files bellow. Let me know if you want the full project.

=== ===
package test;

import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.fileupload.FileItem;
import org.apache.commons.fileupload.disk.DiskFileItemFactory;
import org.apache.commons.fileupload.servlet.ServletFileUpload;
import org.mortbay.jetty.Handler;
import org.mortbay.jetty.Server;
import org.mortbay.jetty.handler.AbstractHandler;

 * @author Keith Kowalczykowski
public class Main {

	public static void main(String[] args) {
		Handler handler = new AbstractHandler() {

			public void handle(String arg0, HttpServletRequest arg1,
					HttpServletResponse arg2, int arg3) throws IOException,
				System.out.println("Starting processing");
					 // Create a factory for disk-based file items
		            DiskFileItemFactory factory = new DiskFileItemFactory();
		            // Create a new file upload handler
		            ServletFileUpload upload = new ServletFileUpload(factory);
		            // Parse the request
		            List items = upload.parseRequest(arg1);

		            for (int i = 0; i < items.size(); i++)
		                FileItem file_item = (FileItem) items.get(i);
		                System.out.println("Field Name: " + file_item.getFieldName());
				catch (Exception e)
					System.out.println("Exception occured in processing");
					System.out.println("Processing completed");


			Server server = new Server(8080);
		catch (Exception e)

=== HTML Document ===
        <form name="test" action="http://localhost:8080/" method="post" enctype="multipart/form-data">
            <input type="file" name="fileupload"/>
            <input type="submit"/>

This message is automatically generated by JIRA.
You can reply to this email to add a comment to the issue online.

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message