Details
-
Bug
-
Status: Closed
-
Minor
-
Resolution: Fixed
-
3.1.2
-
None
-
windows jdk 1.8
-
Unknown
Description
When using the demo.hw.server.HelloWorld client from different threads a data race occurs in org/apache/cxf/transport/http/HTTPConduit.prepare:
if (this.authSupplier == null)
{ this.authSupplier = createAuthSupplier(effectiveAuthPolicy.getAuthorizationType()); }I would suggest to make the field authSupplier volatile.
Here is my Test client:
public class TestCxfClient extends MultiThreadedOneInstanceTemplate {
private static final QName SERVICE_NAME
= new QName("http://server.hw.demo/", "HelloWorld");
private static final QName PORT_NAME
= new QName("http://server.hw.demo/", "HelloWorldPort");
private final HelloWorld hw;
public TestCxfClient(HelloWorld hw)
{ super(); this.hw = hw; }public void exec()
{ System.out.println(hw.sayHi("World")); }public static void main(String[] args) throws Exception
{ Service service = Service.create(SERVICE_NAME); // Endpoint Address String endpointAddress = "http://localhost:8080/java_first_jaxws/services/hello_world"; // If web service deployed on Tomcat (either standalone or embedded) // as described in sample README, endpoint should be changed to: // String endpointAddress = "http://localhost:8080/java_first_jaxws/services/hello_world"; // Add a port to the Service service.addPort(PORT_NAME, SOAPBinding.SOAP11HTTP_BINDING, endpointAddress); HelloWorld hw = service.getPort(HelloWorld.class); (new TestCxfClient(hw)).test(); }}
public abstract class MultiThreadedOneInstanceTemplate implements Runnable {
private final AtomicInteger threadCount = new AtomicInteger();
public void test() throws Exception
{
for(int i = 0; i < 2 ;i++)
while( this.threadCount.get() > 0 )
{ Thread.sleep(1000); } Thread.sleep(10 * 1000);
}
public void run()
{ exec(); threadCount.decrementAndGet(); }protected abstract void exec();
}
Data Race was found by http://vmlens.com