View | Details | Raw Unified | Return to bug 58807
Collapse All | Expand All

(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC3Impl.java (-6 / +34 lines)
Lines 112-119 Link Here
112
    // Needs to be accessible by HTTPSampler2
112
    // Needs to be accessible by HTTPSampler2
113
    volatile HttpClient savedClient;
113
    volatile HttpClient savedClient;
114
114
115
    private volatile boolean resetSSLContext;
115
    private static final ThreadLocal<Boolean> closeConnections = 
116
        new ThreadLocal<Boolean>(){
117
        @Override
118
        protected Boolean initialValue() {
119
            return new Boolean(false);
120
        }
121
    };
116
122
123
    private static final ThreadLocal<Boolean> resetHTTPClient = 
124
        new ThreadLocal<Boolean>(){
125
        @Override
126
        protected Boolean initialValue() {
127
            return new Boolean(false);
128
        }
129
    };
130
131
117
    static {
132
    static {
118
        log.info("HTTP request retry count = "+RETRY_COUNT);
133
        log.info("HTTP request retry count = "+RETRY_COUNT);
119
        if (CPS_HTTP > 0) {
134
        if (CPS_HTTP > 0) {
Lines 470-481 Link Here
470
        // N.B. HostConfiguration.equals() includes proxy settings in the compare.
485
        // N.B. HostConfiguration.equals() includes proxy settings in the compare.
471
        HttpClient httpClient = map.get(hc);
486
        HttpClient httpClient = map.get(hc);
472
487
473
        if (httpClient != null && resetSSLContext && isHTTPS) {
488
        if (closeConnections.get()) {
474
            httpClient.getHttpConnectionManager().closeIdleConnections(-1000);
489
            for (HttpClient cl : map.values()) {
475
            httpClient = null;
490
                cl.getHttpConnectionManager().closeIdleConnections(-1000);
491
            }
492
            closeConnections.set(false);
493
        }
494
        if (resetHTTPClient.get()) {
495
            if (httpClient != null) {
496
                httpClient = null;
497
            }
498
            resetHTTPClient.set(false);
499
        }
500
        if (resetSSLContext.get() && isHTTPS) {
476
            JsseSSLManager sslMgr = (JsseSSLManager) SSLManager.getInstance();
501
            JsseSSLManager sslMgr = (JsseSSLManager) SSLManager.getInstance();
477
            sslMgr.resetContext();
502
            sslMgr.resetContext();
478
            resetSSLContext = false;
503
            resetSSLContext.set(false);
479
        }
504
        }
480
505
481
        if ( httpClient == null )
506
        if ( httpClient == null )
Lines 1117-1124 Link Here
1117
1142
1118
    @Override
1143
    @Override
1119
    protected void notifyFirstSampleAfterLoopRestart() {
1144
    protected void notifyFirstSampleAfterLoopRestart() {
1145
        // see https://bz.apache.org/bugzilla/show_bug.cgi?id=51380
1120
        log.debug("notifyFirstSampleAfterLoopRestart");
1146
        log.debug("notifyFirstSampleAfterLoopRestart");
1121
        resetSSLContext = !USE_CACHED_SSL_CONTEXT;
1147
        closeConnections.set(!REUSE_HTTP_CONNECTIONS);
1148
        resetHTTPClient.set(!REUSE_HTTP_CLIENT);
1149
        resetSSLContext.set(!USE_CACHED_SSL_CONTEXT);
1122
    }
1150
    }
1123
1151
1124
    /**
1152
    /**
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHC4Impl.java (-8 / +35 lines)
Lines 253-260 Link Here
253
253
254
    private volatile HttpUriRequest currentRequest; // Accessed from multiple threads
254
    private volatile HttpUriRequest currentRequest; // Accessed from multiple threads
255
255
256
    private volatile boolean resetSSLContext;
256
    private static final ThreadLocal<Boolean> closeConnections =
257
        new ThreadLocal<Boolean>(){
258
        @Override
259
        protected Boolean initialValue() {
260
            return new Boolean(false);
261
        }
262
    };
257
263
264
    private static final ThreadLocal<Boolean> resetHTTPClient =
265
        new ThreadLocal<Boolean>(){
266
        @Override
267
        protected Boolean initialValue() {
268
            return new Boolean(false);
269
        }
270
    };
271
258
    protected HTTPHC4Impl(HTTPSamplerBase testElement) {
272
    protected HTTPHC4Impl(HTTPSamplerBase testElement) {
259
        super(testElement);
273
        super(testElement);
260
    }
274
    }
Lines 697-710 Link Here
697
        
711
        
698
        HttpClient httpClient = mapHttpClientPerHttpClientKey.get(key);
712
        HttpClient httpClient = mapHttpClientPerHttpClientKey.get(key);
699
713
700
        if (httpClient != null && resetSSLContext && HTTPConstants.PROTOCOL_HTTPS.equalsIgnoreCase(url.getProtocol())) {
714
        if (closeConnections.get()) {
701
            ((AbstractHttpClient) httpClient).clearRequestInterceptors(); 
715
            for (HttpClient cl : mapHttpClientPerHttpClientKey.values()) {
702
            ((AbstractHttpClient) httpClient).clearResponseInterceptors(); 
716
                cl.getConnectionManager().closeIdleConnections(1L, TimeUnit.MICROSECONDS);
703
            httpClient.getConnectionManager().closeIdleConnections(1L, TimeUnit.MICROSECONDS);
717
            }
704
            httpClient = null;
718
            closeConnections.set(false);
719
        }
720
        if (resetHTTPClient.get()) {
721
            if (httpClient != null) {
722
                ((AbstractHttpClient) httpClient).clearRequestInterceptors(); 
723
                ((AbstractHttpClient) httpClient).clearResponseInterceptors(); 
724
                httpClient = null;
725
            }
726
            resetHTTPClient.set(false);
727
        }
728
        if (resetSSLContext.get() && HTTPConstants.PROTOCOL_HTTPS.equalsIgnoreCase(url.getProtocol())) {
705
            JsseSSLManager sslMgr = (JsseSSLManager) SSLManager.getInstance();
729
            JsseSSLManager sslMgr = (JsseSSLManager) SSLManager.getInstance();
706
            sslMgr.resetContext();
730
            sslMgr.resetContext();
707
            resetSSLContext = false;
731
            resetSSLContext.set(false);
708
        }
732
        }
709
733
710
        if (httpClient == null){ // One-time init for this client
734
        if (httpClient == null){ // One-time init for this client
Lines 1395-1402 Link Here
1395
1419
1396
    @Override
1420
    @Override
1397
    protected void notifyFirstSampleAfterLoopRestart() {
1421
    protected void notifyFirstSampleAfterLoopRestart() {
1422
        // see https://bz.apache.org/bugzilla/show_bug.cgi?id=51380
1398
        log.debug("notifyFirstSampleAfterLoopRestart");
1423
        log.debug("notifyFirstSampleAfterLoopRestart");
1399
        resetSSLContext = !USE_CACHED_SSL_CONTEXT;
1424
        closeConnections.set(!REUSE_HTTP_CONNECTIONS);
1425
        resetHTTPClient.set(!REUSE_HTTP_CLIENT);
1426
        resetSSLContext.set(!USE_CACHED_SSL_CONTEXT);
1400
    }
1427
    }
1401
1428
1402
    @Override
1429
    @Override
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPHCAbstractImpl.java (+17 lines)
Lines 78-87 Link Here
78
    // -1 means not defined
78
    // -1 means not defined
79
    protected static final int SO_TIMEOUT = JMeterUtils.getPropDefault("httpclient.timeout", -1);
79
    protected static final int SO_TIMEOUT = JMeterUtils.getPropDefault("httpclient.timeout", -1);
80
    
80
    
81
    // Control reuse of HTTP connections in subsequent iterations
82
    protected static final boolean REUSE_HTTP_CONNECTIONS = 
83
            JMeterUtils.getPropDefault("reuse.http.connections", true);//$NON-NLS-1$
84
85
    // Control reuse of HTTPClient in subsequent iterations
86
    protected static final boolean REUSE_HTTP_CLIENT = 
87
            JMeterUtils.getPropDefault("reuse.http.client", true);//$NON-NLS-1$
88
81
    // Control reuse of cached SSL Context in subsequent iterations
89
    // Control reuse of cached SSL Context in subsequent iterations
82
    protected static final boolean USE_CACHED_SSL_CONTEXT = 
90
    protected static final boolean USE_CACHED_SSL_CONTEXT = 
83
            JMeterUtils.getPropDefault("https.use.cached.ssl.context", true);//$NON-NLS-1$
91
            JMeterUtils.getPropDefault("https.use.cached.ssl.context", true);//$NON-NLS-1$
84
92
93
    // Shared state for any HC based implementation, because SSL contexts are the same
94
    protected static final ThreadLocal<Boolean> resetSSLContext =
95
        new ThreadLocal<Boolean>(){
96
        @Override
97
        protected Boolean initialValue() {
98
            return new Boolean(false);
99
        }
100
    };
101
85
    static {
102
    static {
86
        if(!StringUtils.isEmpty(JMeterUtils.getProperty("httpclient.timeout"))) { //$NON-NLS-1$
103
        if(!StringUtils.isEmpty(JMeterUtils.getProperty("httpclient.timeout"))) { //$NON-NLS-1$
87
            log.warn("You're using property 'httpclient.timeout' that will soon be deprecated for HttpClient3.1, you should either set "
104
            log.warn("You're using property 'httpclient.timeout' that will soon be deprecated for HttpClient3.1, you should either set "
(-)src/protocol/http/org/apache/jmeter/protocol/http/sampler/HTTPSamplerProxy.java (-8 / +3 lines)
Lines 36-43 Link Here
36
36
37
    private transient HTTPAbstractImpl impl;
37
    private transient HTTPAbstractImpl impl;
38
    
38
    
39
    private transient volatile boolean notifyFirstSampleAfterLoopRestart;
40
41
    public HTTPSamplerProxy(){
39
    public HTTPSamplerProxy(){
42
        super();
40
        super();
43
    }
41
    }
Lines 66-76 Link Here
66
                return errorResult(ex, new HTTPSampleResult());
64
                return errorResult(ex, new HTTPSampleResult());
67
            }
65
            }
68
        }
66
        }
69
        // see https://bz.apache.org/bugzilla/show_bug.cgi?id=51380
70
        if(notifyFirstSampleAfterLoopRestart) {
71
            impl.notifyFirstSampleAfterLoopRestart();
72
            notifyFirstSampleAfterLoopRestart = false;
73
        }
74
        return impl.sample(u, method, areFollowingRedirect, depth);
67
        return impl.sample(u, method, areFollowingRedirect, depth);
75
    }
68
    }
76
69
Lines 97-102 Link Here
97
     */
90
     */
98
    @Override
91
    @Override
99
    public void testIterationStart(LoopIterationEvent event) {
92
    public void testIterationStart(LoopIterationEvent event) {
100
        notifyFirstSampleAfterLoopRestart = true;
93
        if (impl != null) {
94
            impl.notifyFirstSampleAfterLoopRestart();
95
        }
101
    }
96
    }
102
}
97
}

Return to bug 58807