Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
5e80a71a
Commit
5e80a71a
authored
Mar 10, 2018
by
Andrew Svetlov
Committed by
GitHub
Mar 10, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
bpo-33037: Skip sending/receiving after SSL transport closing (GH-6044)
* Skip write()/data_received() if sslpipe is destroyed
parent
496431ff
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
43 additions
and
21 deletions
+43
-21
Lib/asyncio/sslproto.py
Lib/asyncio/sslproto.py
+5
-1
Lib/test/test_asyncio/test_sslproto.py
Lib/test/test_asyncio/test_sslproto.py
+37
-20
Misc/NEWS.d/next/Library/2018-03-09-23-07-07.bpo-33037.nAJ3at.rst
...S.d/next/Library/2018-03-09-23-07-07.bpo-33037.nAJ3at.rst
+1
-0
No files found.
Lib/asyncio/sslproto.py
View file @
5e80a71a
...
...
@@ -504,6 +504,10 @@ class SSLProtocol(protocols.Protocol):
The argument is a bytes object.
"""
if
self
.
_sslpipe
is
None
:
# transport closing, sslpipe is destroyed
return
try
:
ssldata
,
appdata
=
self
.
_sslpipe
.
feed_ssldata
(
data
)
except
ssl
.
SSLError
as
e
:
...
...
@@ -636,7 +640,7 @@ class SSLProtocol(protocols.Protocol):
def
_process_write_backlog
(
self
):
# Try to make progress on the write backlog.
if
self
.
_transport
is
None
:
if
self
.
_transport
is
None
or
self
.
_sslpipe
is
None
:
return
try
:
...
...
Lib/test/test_asyncio/test_sslproto.py
View file @
5e80a71a
...
...
@@ -26,16 +26,17 @@ class SslProtoHandshakeTests(test_utils.TestCase):
self
.
loop
=
asyncio
.
new_event_loop
()
self
.
set_event_loop
(
self
.
loop
)
def
ssl_protocol
(
self
,
waiter
=
None
):
def
ssl_protocol
(
self
,
*
,
waiter
=
None
,
proto
=
None
):
sslcontext
=
test_utils
.
dummy_ssl_context
()
app_proto
=
asyncio
.
Protocol
()
proto
=
sslproto
.
SSLProtocol
(
self
.
loop
,
app_proto
,
sslcontext
,
waiter
,
if
proto
is
None
:
# app protocol
proto
=
asyncio
.
Protocol
()
ssl_proto
=
sslproto
.
SSLProtocol
(
self
.
loop
,
proto
,
sslcontext
,
waiter
,
ssl_handshake_timeout
=
0.1
)
self
.
assertIs
(
proto
.
_app_transport
.
get_protocol
(),
app_
proto
)
self
.
addCleanup
(
proto
.
_app_transport
.
close
)
return
proto
self
.
assertIs
(
ssl_proto
.
_app_transport
.
get_protocol
(),
proto
)
self
.
addCleanup
(
ssl_
proto
.
_app_transport
.
close
)
return
ssl_
proto
def
connection_made
(
self
,
ssl_proto
,
do_handshake
=
None
):
def
connection_made
(
self
,
ssl_proto
,
*
,
do_handshake
=
None
):
transport
=
mock
.
Mock
()
sslpipe
=
mock
.
Mock
()
sslpipe
.
shutdown
.
return_value
=
b''
...
...
@@ -53,7 +54,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
# Python issue #23197: cancelling a handshake must not raise an
# exception or log an error, even if the handshake failed
waiter
=
asyncio
.
Future
(
loop
=
self
.
loop
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
=
waiter
)
handshake_fut
=
asyncio
.
Future
(
loop
=
self
.
loop
)
def
do_handshake
(
callback
):
...
...
@@ -63,7 +64,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
return
[]
waiter
.
cancel
()
self
.
connection_made
(
ssl_proto
,
do_handshake
)
self
.
connection_made
(
ssl_proto
,
do_handshake
=
do_handshake
)
with
test_utils
.
disable_logger
():
self
.
loop
.
run_until_complete
(
handshake_fut
)
...
...
@@ -96,7 +97,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
def
test_eof_received_waiter
(
self
):
waiter
=
asyncio
.
Future
(
loop
=
self
.
loop
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
=
waiter
)
self
.
connection_made
(
ssl_proto
)
ssl_proto
.
eof_received
()
test_utils
.
run_briefly
(
self
.
loop
)
...
...
@@ -107,7 +108,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
# _fatal_error() generates a NameError if sslproto.py
# does not import base_events.
waiter
=
asyncio
.
Future
(
loop
=
self
.
loop
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
=
waiter
)
# Temporarily turn off error logging so as not to spoil test output.
log_level
=
log
.
logger
.
getEffectiveLevel
()
log
.
logger
.
setLevel
(
logging
.
FATAL
)
...
...
@@ -121,7 +122,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
# From issue #472.
# yield from waiter hang if lost_connection was called.
waiter
=
asyncio
.
Future
(
loop
=
self
.
loop
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
=
waiter
)
self
.
connection_made
(
ssl_proto
)
ssl_proto
.
connection_lost
(
ConnectionAbortedError
)
test_utils
.
run_briefly
(
self
.
loop
)
...
...
@@ -130,10 +131,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
def
test_close_during_handshake
(
self
):
# bpo-29743 Closing transport during handshake process leaks socket
waiter
=
asyncio
.
Future
(
loop
=
self
.
loop
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
)
def
do_handshake
(
callback
):
return
[]
ssl_proto
=
self
.
ssl_protocol
(
waiter
=
waiter
)
transport
=
self
.
connection_made
(
ssl_proto
)
test_utils
.
run_briefly
(
self
.
loop
)
...
...
@@ -143,7 +141,7 @@ class SslProtoHandshakeTests(test_utils.TestCase):
def
test_get_extra_info_on_closed_connection
(
self
):
waiter
=
asyncio
.
Future
(
loop
=
self
.
loop
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
=
waiter
)
self
.
assertIsNone
(
ssl_proto
.
_get_extra_info
(
'socket'
))
default
=
object
()
self
.
assertIs
(
ssl_proto
.
_get_extra_info
(
'socket'
,
default
),
default
)
...
...
@@ -154,12 +152,31 @@ class SslProtoHandshakeTests(test_utils.TestCase):
def
test_set_new_app_protocol
(
self
):
waiter
=
asyncio
.
Future
(
loop
=
self
.
loop
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
)
ssl_proto
=
self
.
ssl_protocol
(
waiter
=
waiter
)
new_app_proto
=
asyncio
.
Protocol
()
ssl_proto
.
_app_transport
.
set_protocol
(
new_app_proto
)
self
.
assertIs
(
ssl_proto
.
_app_transport
.
get_protocol
(),
new_app_proto
)
self
.
assertIs
(
ssl_proto
.
_app_protocol
,
new_app_proto
)
def
test_data_received_after_closing
(
self
):
ssl_proto
=
self
.
ssl_protocol
()
self
.
connection_made
(
ssl_proto
)
transp
=
ssl_proto
.
_app_transport
transp
.
close
()
# should not raise
self
.
assertIsNone
(
ssl_proto
.
data_received
(
b'data'
))
def
test_write_after_closing
(
self
):
ssl_proto
=
self
.
ssl_protocol
()
self
.
connection_made
(
ssl_proto
)
transp
=
ssl_proto
.
_app_transport
transp
.
close
()
# should not raise
self
.
assertIsNone
(
transp
.
write
(
b'data'
))
##############################################################################
# Start TLS Tests
...
...
Misc/NEWS.d/next/Library/2018-03-09-23-07-07.bpo-33037.nAJ3at.rst
0 → 100644
View file @
5e80a71a
Skip sending/receiving data after SSL transport closing.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment