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