hc-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Richard Evans (Commented) (JIRA)" <j...@apache.org>
Subject [jira] [Commented] (HTTPASYNC-6) I/O reactor (client) terminates abnormally when a connection is prematurely closed probably because of timeout settings. A NullpointerException is thrown when a response is being read and the connection is already closed and set to null
Date Mon, 21 Nov 2011 23:09:40 GMT

    [ https://issues.apache.org/jira/browse/HTTPASYNC-6?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=13154714#comment-13154714
] 

Richard Evans commented on HTTPASYNC-6:
---------------------------------------

The following code on alpha3 demonstrates this problem. Of course it is assuming that the
code is valid. I was trying to see if this library supported multi threaded asynch http.


package org.apache.http.examples.nio.client;

import java.util.concurrent.CountDownLatch;

import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.concurrent.FutureCallback;
import org.apache.http.impl.nio.client.DefaultHttpAsyncClient;
import org.apache.http.impl.nio.conn.PoolingAsyncClientConnectionManager;
import org.apache.http.impl.nio.reactor.DefaultConnectingIOReactor;
import org.apache.http.nio.client.HttpAsyncClient;
import org.apache.http.params.CoreConnectionPNames;

public class AsyncClientHttpExchangeFutureCallback {

    public static void main(String[] args) throws Exception {
    	initialiseLogging();
        HttpAsyncClient httpclient = new DefaultHttpAsyncClient(new PoolingAsyncClientConnectionManager(new
DefaultConnectingIOReactor()));
        httpclient.getParams()
            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 3000)
            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 3000)
            .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024)
            .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true);

        httpclient.start();
            
        int numberOfThreads = 4;
        Thread [] thread = new Thread[numberOfThreads];
        for (int j = 0; j < numberOfThreads; j++) 
        {
			thread[j] = new Thread(new Worker(httpclient));
		}
        
        Thread.currentThread().sleep(100);
        for (int j = 0; j < numberOfThreads; j++) 
        {
			thread[j].start();
		}
        
        for (int j = 0; j < numberOfThreads; j++) 
        {
			thread[j].join();
		}   
        System.out.println("Done");
        
        httpclient.shutdown();
    }

	private static void initialiseLogging() {
		java.util.logging.Logger.getLogger("org.apache.http.wire").setLevel(java.util.logging.Level.FINEST);
		java.util.logging.Logger.getLogger("org.apache.http.headers").setLevel(java.util.logging.Level.FINEST);

		System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SimpleLog");
		System.setProperty("org.apache.commons.logging.simplelog.showdatetime", "true");
		System.setProperty("org.apache.commons.logging.simplelog.log.httpclient.wire", "debug");
		System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http", "debug");
		System.setProperty("org.apache.commons.logging.simplelog.log.org.apache.http.headers", "debug");
	
	}

	
}

class Worker implements Runnable
{
	private HttpAsyncClient httpclient;
	
	public Worker(HttpAsyncClient httpclient)
	{
		this.httpclient = httpclient;
	}
	
	public void run()
	{
			
		HttpGet[] requests = new HttpGet[] {
		        new HttpGet("http://www.apache.org/"),
		        new HttpGet("http://www.google.com/")
		};
		final CountDownLatch latch = new CountDownLatch(requests.length);
		for (final HttpGet request: requests) {
		    httpclient.execute(request, new FutureCallback<HttpResponse>() {

		        public void completed(final HttpResponse response) {
		            latch.countDown();
		            System.out.println(request.getRequestLine() + "->" + response.getStatusLine());
		        }

		        public void failed(final Exception ex) {
		            latch.countDown();
		            System.out.println(request.getRequestLine() + "->" + ex);
		        }

		        public void cancelled() {
		            latch.countDown();
		            System.out.println(request.getRequestLine() + " cancelled");
		        }

		    });
		}
		try {
			latch.await();
		} catch (InterruptedException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
}
                
> I/O reactor (client) terminates abnormally when a connection is prematurely closed probably
because of timeout settings. A NullpointerException is thrown when a response is being read
and the connection is already closed and set to null
> --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: HTTPASYNC-6
>                 URL: https://issues.apache.org/jira/browse/HTTPASYNC-6
>             Project: HttpComponents HttpAsyncClient
>          Issue Type: Bug
>    Affects Versions: 4.0-alpha2
>         Environment: Windows Vista , Sun Java SDK 1.6.0_26
>            Reporter: Menno van Gangelen
>            Priority: Critical
>             Fix For: 4.0-alpha3
>
>
> The following line should have a check for null.
> org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.responseCompleted(DefaultAsyncRequestDirector.java:366);
> =>           if (this.managedConn.isOpen()) {
> Hard to reproduce as it seems to be a racing issue when reading from slow websites.
> 2011-09-03 10:40:53,312 [I/O dispatcher 2] ERROR DefaultHttpAsyncClient - Fatal runtime
error
> java.lang.NullPointerException
> 	at org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.responseCompleted(DefaultAsyncRequestDirector.java:366)
> 	at org.apache.http.impl.nio.client.NHttpClientProtocolHandler.processResponse(NHttpClientProtocolHandler.java:357)
> 	at org.apache.http.impl.nio.client.NHttpClientProtocolHandler.inputReady(NHttpClientProtocolHandler.java:196)
> 	at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:172)
> 	at org.apache.http.impl.nio.client.InternalClientEventDispatch.inputReady(InternalClientEventDispatch.java:76)
> 	at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:161)
> 	at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:335)
> 	at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
> 	at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:275)
> 	at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
> 	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:542)
> 	at java.lang.Thread.run(Thread.java:662)
> 2011-09-03 10:40:53,692 [Thread-4] ERROR DefaultHttpAsyncClient - I/O reactor terminated
abnormally
> org.apache.http.nio.reactor.IOReactorException: I/O dispatch worker terminated abnormally
> 	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor.execute(AbstractMultiworkerIOReactor.java:321)
> 	at org.apache.http.impl.nio.conn.PoolingClientConnectionManager.execute(PoolingClientConnectionManager.java:91)
> 	at org.apache.http.impl.nio.client.AbstractHttpAsyncClient.doExecute(AbstractHttpAsyncClient.java:441)
> 	at org.apache.http.impl.nio.client.AbstractHttpAsyncClient.access$000(AbstractHttpAsyncClient.java:95)
> 	at org.apache.http.impl.nio.client.AbstractHttpAsyncClient$1.run(AbstractHttpAsyncClient.java:462)
> Caused by: java.lang.NullPointerException
> 	at org.apache.http.impl.nio.client.DefaultAsyncRequestDirector.responseCompleted(DefaultAsyncRequestDirector.java:366)
> 	at org.apache.http.impl.nio.client.NHttpClientProtocolHandler.processResponse(NHttpClientProtocolHandler.java:357)
> 	at org.apache.http.impl.nio.client.NHttpClientProtocolHandler.inputReady(NHttpClientProtocolHandler.java:196)
> 	at org.apache.http.impl.nio.DefaultNHttpClientConnection.consumeInput(DefaultNHttpClientConnection.java:172)
> 	at org.apache.http.impl.nio.client.InternalClientEventDispatch.inputReady(InternalClientEventDispatch.java:76)
> 	at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:161)
> 	at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:335)
> 	at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
> 	at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:275)
> 	at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
> 	at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:542)
> 	at java.lang.Thread.run(Thread.java:662)
> Subsequent calls fail with the following exception
> java.util.concurrent.ExecutionException: java.lang.IllegalStateException: Client has
been shut down

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@hc.apache.org
For additional commands, e-mail: dev-help@hc.apache.org


Mime
View raw message