@@ -221,41 +221,45 @@ protected void deallocate() { |
221 | 221 | this.jdkCompatibilityMode = jdkCompatibilityMode; |
222 | 222 | Lock readerLock = context.ctxLock.readLock(); |
223 | 223 | readerLock.lock(); |
| 224 | + final long finalSsl; |
224 | 225 | try { |
225 | | - ssl = SSL.newSSL(context.ctx, !context.isClient()); |
| 226 | + finalSsl = SSL.newSSL(context.ctx, !context.isClient()); |
226 | 227 | } finally { |
227 | 228 | readerLock.unlock(); |
228 | 229 | } |
229 | | - try { |
230 | | - networkBIO = SSL.bioNewByteBuffer(ssl, context.getBioNonApplicationBufferSize()); |
| 230 | + synchronized (this) { |
| 231 | + ssl = finalSsl; |
| 232 | + try { |
| 233 | + networkBIO = SSL.bioNewByteBuffer(ssl, context.getBioNonApplicationBufferSize()); |
231 | 234 |
|
232 | | - // Set the client auth mode, this needs to be done via setClientAuth(...) method so we actually call the |
233 | | - // needed JNI methods. |
234 | | - setClientAuth(clientMode ? ClientAuth.NONE : context.clientAuth); |
| 235 | + // Set the client auth mode, this needs to be done via setClientAuth(...) method so we actually call the |
| 236 | + // needed JNI methods. |
| 237 | + setClientAuth(clientMode ? ClientAuth.NONE : context.clientAuth); |
235 | 238 |
|
236 | | - if (context.protocols != null) { |
237 | | - setEnabledProtocols(context.protocols); |
238 | | - } |
| 239 | + if (context.protocols != null) { |
| 240 | + setEnabledProtocols(context.protocols); |
| 241 | + } |
239 | 242 |
|
240 | | - // Use SNI if peerHost was specified |
241 | | - // See https://github.com/netty/netty/issues/4746 |
242 | | - if (clientMode && peerHost != null) { |
243 | | - SSL.setTlsExtHostName(ssl, peerHost); |
244 | | - } |
| 243 | + // Use SNI if peerHost was specified |
| 244 | + // See https://github.com/netty/netty/issues/4746 |
| 245 | + if (clientMode && peerHost != null) { |
| 246 | + SSL.setTlsExtHostName(ssl, peerHost); |
| 247 | + } |
245 | 248 |
|
246 | | - if (enableOcsp) { |
247 | | - SSL.enableOcsp(ssl); |
248 | | - } |
| 249 | + if (enableOcsp) { |
| 250 | + SSL.enableOcsp(ssl); |
| 251 | + } |
249 | 252 |
|
250 | | - if (!jdkCompatibilityMode) { |
251 | | - SSL.setMode(ssl, SSL.getMode(ssl) | SSL.SSL_MODE_ENABLE_PARTIAL_WRITE); |
252 | | - } |
| 253 | + if (!jdkCompatibilityMode) { |
| 254 | + SSL.setMode(ssl, SSL.getMode(ssl) | SSL.SSL_MODE_ENABLE_PARTIAL_WRITE); |
| 255 | + } |
253 | 256 |
|
254 | | - // setMode may impact the overhead. |
255 | | - calculateMaxWrapOverhead(); |
256 | | - } catch (Throwable cause) { |
257 | | - SSL.freeSSL(ssl); |
258 | | - PlatformDependent.throwException(cause); |
| 257 | + // setMode may impact the overhead. |
| 258 | + calculateMaxWrapOverhead(); |
| 259 | + } catch (Throwable cause) { |
| 260 | + SSL.freeSSL(ssl); |
| 261 | + PlatformDependent.throwException(cause); |
| 262 | + } |
259 | 263 | } |
260 | 264 | } |
261 | 265 |
|
|