Bug 298156 - [api] provide method for canceling HTTP requests without blocking
Summary: [api] provide method for canceling HTTP requests without blocking
Status: RESOLVED FIXED
Alias: None
Product: z_Archived
Classification: Eclipse Foundation
Component: Mylyn (show other bugs)
Version: unspecified   Edit
Hardware: PC Windows XP
: P2 enhancement (vote)
Target Milestone: 3.4   Edit
Assignee: Steffen Pingel CLA
QA Contact:
URL:
Whiteboard:
Keywords: noteworthy
Depends on: 255417
Blocks:
  Show dependency tree
 
Reported: 2009-12-18 05:20 EST by Andreas Höhmann CLA
Modified: 2010-04-23 21:48 EDT (History)
3 users (show)

See Also:


Attachments
screenshot of query page (119.54 KB, image/png)
2009-12-18 05:21 EST, Andreas Höhmann CLA
no flags Details
proposed fix (2.30 KB, patch)
2010-02-07 23:12 EST, Steffen Pingel CLA
no flags Details | Diff
mylyn/context/zip (17.01 KB, application/octet-stream)
2010-02-07 23:13 EST, Steffen Pingel CLA
no flags Details
improved patch (13.37 KB, patch)
2010-03-04 18:48 EST, Steffen Pingel CLA
no flags Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Andreas Höhmann CLA 2009-12-18 05:20:19 EST
Build Identifier: 

I would be nice if the cancel will done immediately.
Maybe this is not possible if a "external" (none java) library 
is called but I think this is all pure java :)

Reproducible: Didn't try

Steps to Reproduce:
1. "new query"
2. ... search options update starts ...
3. click "cancel"
4. but then the update is still running ... (a long time)
Comment 1 Andreas Höhmann CLA 2009-12-18 05:21:28 EST
Created attachment 154754 [details]
screenshot of query page

If I clicked "cancel" the query page is in " deathlock" state.
I can't close the dialog, because the update is still running.
Comment 2 Steffen Pingel CLA 2010-01-03 01:57:04 EST
The problem is the stream is exhausted upon cancel instead of closing the connection right away. Rob, we'll need a utility method to handle that case as this is a general problem that affects all connectors.

Stack trace for Bugzilla:
	
"ModalContext" prio=10 tid=0x6f8fdc00 nid=0x7199 runnable [0x6f4ad000]
   java.lang.Thread.State: RUNNABLE
	at java.net.SocketInputStream.socketRead0(Native Method)
	at java.net.SocketInputStream.read(SocketInputStream.java:129)
	at java.io.BufferedInputStream.fill(BufferedInputStream.java:218)
	at java.io.BufferedInputStream.read1(BufferedInputStream.java:258)
	at java.io.BufferedInputStream.read(BufferedInputStream.java:317)
	- locked <0xad18b9a8> (a java.io.BufferedInputStream)
	at org.apache.commons.httpclient.ContentLengthInputStream.read(ContentLengthInputStream.java:170)
	at org.apache.commons.httpclient.ContentLengthInputStream.read(ContentLengthInputStream.java:184)
	at org.apache.commons.httpclient.ChunkedInputStream.exhaustInputStream(ChunkedInputStream.java:369)
	at org.apache.commons.httpclient.ContentLengthInputStream.close(ContentLengthInputStream.java:118)
	at java.io.FilterInputStream.close(FilterInputStream.java:155)
	at org.apache.commons.httpclient.AutoCloseInputStream.notifyWatcher(AutoCloseInputStream.java:194)
	at org.apache.commons.httpclient.AutoCloseInputStream.close(AutoCloseInputStream.java:158)
	at org.apache.commons.httpclient.HttpMethodBase.releaseConnection(HttpMethodBase.java:1181)
	at org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient.getRepositoryConfiguration(BugzillaClient.java:643)
	at org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector.getRepositoryConfiguration(BugzillaRepositoryConnector.java:722)
	- locked <0xb0beb340> (a java.util.HashMap)
	at org.eclipse.mylyn.internal.bugzilla.ui.search.BugzillaSearchPage$11.run(BugzillaSearchPage.java:1884)
	at org.eclipse.jface.operation.ModalContext$ModalContextThread.run(ModalContext.java:121)
Comment 3 Steffen Pingel CLA 2010-02-07 23:12:59 EST
Created attachment 158412 [details]
proposed fix
Comment 4 Steffen Pingel CLA 2010-02-07 23:13:04 EST
Created attachment 158413 [details]
mylyn/context/zip
Comment 5 Steffen Pingel CLA 2010-02-07 23:24:33 EST
Rob, Shawn, please take a look at the proposed change and let me know what you think. We would need to change every call to method.releaseConnection() to go through WebUtil and pass the progress monitor along and remove calls to stream.close() which I missed in the patch.
Comment 6 Shawn Minto CLA 2010-02-08 12:07:47 EST
That looks good to me.
Comment 7 Steffen Pingel CLA 2010-03-04 18:48:06 EST
Created attachment 161051 [details]
improved patch
Comment 8 Steffen Pingel CLA 2010-03-04 18:51:14 EST
Need to postpone applying patch until bug 304755 is resolved since org.eclipse.mylyn.commons.net has a fixed version and this change adds API.

Remaining work: 
- check remaining invocations of method.releaseConnection()
- check invocations of WebUtil.getResponseBodyAsStream() or re-implement close() in returned stream
Comment 9 Steffen Pingel CLA 2010-03-16 16:57:46 EDT
Also need to consider the case where a connection release is already in progress when a request is cancelled:

"Worker-24" prio=5 tid=0x455d4800 nid=0xb15d8000 waiting for monitor entry [0xb15d7000]
  java.lang.Thread.State: BLOCKED (on object monitor)
       at java.io.BufferedInputStream.read(BufferedInputStream.java:308)
       - waiting to lock <0x27a8e538> (a java.io.BufferedInputStream)
       at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:182)
       at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:196)
       at org.apache.commons.httpclient.ChunkedInputStream.exhaustInputStream(ChunkedInputStream.java:369)
       at org.apache.commons.httpclient.ChunkedInputStream.close(ChunkedInputStream.java:346)
       at java.io.FilterInputStream.close(FilterInputStream.java:155)
       at org.apache.commons.httpclient.AutoCloseInputStream.notifyWatcher(AutoCloseInputStream.java:194)
       at org.apache.commons.httpclient.AutoCloseInputStream.close(AutoCloseInputStream.java:158)
       at org.apache.commons.httpclient.HttpMethodBase.releaseConnection(HttpMethodBase.java:1181)

"Worker-24" prio=5 tid=0x455d4800 nid=0xb15d8000 waiting for monitor entry [0xb15d7000]
  java.lang.Thread.State: BLOCKED (on object monitor)
       at java.io.BufferedInputStream.read(BufferedInputStream.java:308)
       - waiting to lock <0x27a8e538> (a java.io.BufferedInputStream)
       at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:182)
       at org.apache.commons.httpclient.ChunkedInputStream.read(ChunkedInputStream.java:196)
       at org.apache.commons.httpclient.ChunkedInputStream.exhaustInputStream(ChunkedInputStream.java:369)
       at org.apache.commons.httpclient.ChunkedInputStream.close(ChunkedInputStream.java:346)
       at java.io.FilterInputStream.close(FilterInputStream.java:155)
       at org.apache.commons.httpclient.AutoCloseInputStream.notifyWatcher(AutoCloseInputStream.java:194)
       at org.apache.commons.httpclient.AutoCloseInputStream.close(AutoCloseInputStream.java:158)
       at org.apache.commons.httpclient.HttpMethodBase.releaseConnection(HttpMethodBase.java:1181)
Comment 10 Steffen Pingel CLA 2010-04-23 19:35:21 EDT
I have committed the patch.