Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read this important communication.
Bug 341171 - Locking in HttpDestination blocks all requests to the same address
Summary: Locking in HttpDestination blocks all requests to the same address
Status: RESOLVED FIXED
Alias: None
Product: Jetty
Classification: RT
Component: client (show other bugs)
Version: unspecified   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 7.2.x   Edit
Assignee: Simone Bordet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-03-28 17:23 EDT by Chris Dumoulin CLA
Modified: 2011-04-04 10:30 EDT (History)
2 users (show)

See Also:


Attachments
Patch for a proposed fix. (4.73 KB, patch)
2011-03-28 17:27 EDT, Chris Dumoulin CLA
no flags Details | Diff
Different diff format for proposed patch (3.54 KB, patch)
2011-03-28 17:36 EDT, Chris Dumoulin CLA
simone.bordet: iplog+
Details | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Chris Dumoulin CLA 2011-03-28 17:23:28 EDT
Build Identifier: Jetty distribution 7.2.0.v20101020

In org.eclipse.jetty.client.HttpDestination calls to startNewConnection() are being made from within synchronized blocks. During the startNewConnection() call, all HttpConnections for that HttpDestination are blocked from being returned to the HttpDestination and calls to HttpDestination.getIdleConnection() are also blocked.

Since creating a new socket connection can be very slow and startNewConnection() doesn't need to be called from within a synchronized block, calls to startNewConnection() should be moved outside of synchronized blocks.

This is safe because:
- startNewConnection itself performs necessary synchronization to update _pendingConnections.
- The call to connector.startConnection() doesn't need to be synchronized.
- The call to connector.startConnection() will result in one of: onConnectionFailed(), onException(), or onNewConnection() being called. Each of which handles necessary synchronization.

I'll be attaching a patch with a proposed fix.

Reproducible: Always

Steps to Reproduce:
1. Make multiple simultaneous requests to the same web server.
2. Force the server to be slow in accepting one of the connections.
3. Observe that getIdleConnection() and returnConnection() will both block while the slow connection is being made.
Comment 1 Chris Dumoulin CLA 2011-03-28 17:27:34 EDT
Created attachment 192045 [details]
Patch for a proposed fix.
Comment 2 Chris Dumoulin CLA 2011-03-28 17:36:55 EDT
Created attachment 192046 [details]
Different diff format for proposed patch

I'm not sure about the diff format of my initial patch file (what's up with the exclamation marks). I created it using "diff -crB" based on some website's advice.

This new file is from an svn diff of the change I'm proposing (I've got a copy of the jetty source in a local subversion repo). If neither of these versions of the patch are acceptable, please let me know the proper way to provide a patch.
Comment 3 Greg Wilkins CLA 2011-04-01 00:05:25 EDT
Simone,

can you review the state of this issue.  It may be that the changes I made to revert to an async connect may prevent the blocking anyway?
Comment 4 Simone Bordet CLA 2011-04-04 09:49:53 EDT
We have enhanced the connect functionality to support blocking style and non blocking style with the SelectConnector, and the default is blocking.
The SocketConnector can only do blocking connects.

So I am reviewing the patch as we should really attempt to connect outside sync blocks.
Comment 5 Simone Bordet CLA 2011-04-04 10:30:05 EDT
Patch applied with small changes only to variable names.