[Jython-checkins] jython: Ensure SSLHandler context is set when channel becomes active. Workaround for
jim.baker
jython-checkins at python.org
Thu Jan 14 00:44:53 EST 2016
https://hg.python.org/jython/rev/3983294381a0
changeset: 7874:3983294381a0
user: Nick Bailey <nickmbailey at gmail.com>
date: Wed Jan 13 22:44:36 2016 -0700
summary:
Ensure SSLHandler context is set when channel becomes active. Workaround for #2401
Avoids observed race conditions in Netty, depending on how the SSL
handler is added; see https://github.com/netty/netty/issues/4705
files:
ACKNOWLEDGMENTS | 1 +
Lib/ssl.py | 19 +++++++++++++++----
2 files changed, 16 insertions(+), 4 deletions(-)
diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS
--- a/ACKNOWLEDGMENTS
+++ b/ACKNOWLEDGMENTS
@@ -173,6 +173,7 @@
Robert Patrick
Kevin Edwards
Jaime Saiz
+ Nick Bailey
Local Variables:
mode: indented-text
diff --git a/Lib/ssl.py b/Lib/ssl.py
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -138,7 +138,7 @@
}
_cert_name_types = [
- # Fields documented in
+ # Fields documented in
# http://docs.oracle.com/javase/7/docs/api/java/security/cert/X509Certificate.html#getSubjectAlternativeNames()
"other",
"rfc822",
@@ -443,6 +443,17 @@
pipeline = ch.pipeline()
pipeline.addFirst("ssl", self.ssl_handler)
+class RaceFreeSslHandler(SslHandler):
+ """
+ This is a temporary workaround to solve a race condition that is present in
+ Netty 4.0.33. The race condition causes an NPE because 'this.ctx' isn't set when
+ calling channelActive. Once we upgrade to a version of Netty that fixes the race
+ condition, we should remove this.
+ """
+
+ def channelActive(self, ctx):
+ self.ctx = ctx
+ SslHandler.channelActive(self)
class SSLSocket(object):
@@ -502,10 +513,10 @@
self.handshake_count = 0
self.engine = None
-
+
if self.do_handshake_on_connect and self._sock.connected:
if isinstance(self._sock, ChildSocket):
- log.debug("Child socket - do not handshake! type=%s parent=%s", type(self._sock), self._sock.parent_socket,
+ log.debug("Child socket - do not handshake! type=%s parent=%s", type(self._sock), self._sock.parent_socket,
extra={"sock": self._sock})
else:
self.do_handshake()
@@ -599,7 +610,7 @@
self._notify_selectors()
if self.ssl_handler is None:
- self.ssl_handler = SslHandler(self.engine)
+ self.ssl_handler = RaceFreeSslHandler(self.engine)
self.ssl_handler.handshakeFuture().addListener(handshake_step)
if hasattr(self._sock, "connected") and self._sock.connected:
--
Repository URL: https://hg.python.org/jython
More information about the Jython-checkins
mailing list