You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Suppress error "returning true from eof_received() has no effect when using ssl" #859
Could you include a traceback.
It'd be great to have enough information to be able to replicate this - what proxy are you using and what would we need to do to reproduce the issue?
Unfortunately this error is not being caught as an exception. It just prints to the console as I'm running my async function. Sorry for being ignorant, but where should I look to print more information on the error?
I think I've nailed this error down to a specific set of hosts I'm making requests against. I'll try to find any common attributes among those hosts.
The proxy being used is bluecoat proxySG, which afaik uses squid.
I have confirmed that the error also does print when using a squid proxy that does not perform SSL-intercept, otherwise known as "SSL bump".
@lethargy-navigator Thanks for providing a code snippet, but it's still hard to reproduce. Ideally we should be able to copy/paste a bunch of code, run a Python script, and see the error. :-)
Can you, in order of priority:
Share the exact warning you're seeing, and any useful context about it (module, line numbers, etc).
Do some more investigation to pin-point which request exactly triggers the warning (if it's at the request level), and on which host. I'm assuming this will end up being some sort of interaction bettwen verify=False, requesting over HTTPS/HTTP, and perhaps a faulty server.
(FWIW, background on eof_received in the asyncio docs:
Protocol.eof_received():
[...]
Some transports, including SSL, don’t support half-closed connections, in which case returning true from this method will result in the connection being closed.
@florimondmanca
error: "returning true from eof_received() has no effect when using ssl"
Unfortunately this is not caught as an exception so I don't have any details on the module or line number. It just prints to the console while my script is running.
This only affects asyncio when a proxy is used. I could not get the error to print when using trio.
Please see the following code which should allow you to easily reproduce this. This includes 100 randomly selected hosts from att.com.
@amitripshtos Yeah, it seems we closed this prematurely. #54 and the subsequent PR #57 were adressing the "unrelated bug" I was referring to earlier, not the original issue here. Lemme reopen.
The code there uses a ._over_ssl flag to return False in the SSL case, which should prevent the warning from firing, but it does. So maybe that flag is incorrectly set?
I don't think there's actually anything we can do at the HTTPX / HTTPCore level. There's a workaround above, and if this is causing too much trouble I'd recommend filing a ticket to CPython and helping solve the issue over there.
So… I'll actually close this back as "external". :-)
Our own .start_tls() wrapper, which instantiates a StreamReaderProtocol, does not call .connection_made() on it, then passes that to asyncio's start_tls().
So in the end, the StreamReaderProtocol's .connection_made() doesn't get called, so _over_ssl isn't set, and so the warning is logged…
So, how do we fix this?
To fix this, I think we might need to modify our .start_tls() wrapper so it uses the currently running protocol, as follows?
Hi @florimondmanca, thanks for the investigation and the fix.
I understand that the fix is not released as long as encode/httpcore#251 is not merged.
Do you know when it would be available?
@remi-debette Ah, thanks for following up. Indeed I had let the release slip through as I didn't get a review of the changelog there.
Anyone can issue release PRs to HTTPCore, so if you're up for it you could either create a new one based on encode/httpcore#251 (if new PRs got merged to HTTPCore in the meantime), or just review the existing one in case it's up to date. :-) When we're ready I'd just need to merge and release from GitHub UI, but the rest can be contributor driven.
Activity
lovelydinosaur commentedon Mar 11, 2020
Could you include a traceback.
It'd be great to have enough information to be able to replicate this - what proxy are you using and what would we need to do to reproduce the issue?
lethargynavigator commentedon Mar 11, 2020
Unfortunately this error is not being caught as an exception. It just prints to the console as I'm running my async function. Sorry for being ignorant, but where should I look to print more information on the error?
I think I've nailed this error down to a specific set of hosts I'm making requests against. I'll try to find any common attributes among those hosts.
The proxy being used is bluecoat proxySG, which afaik uses squid.
I have confirmed that the error also does print when using a squid proxy that does not perform SSL-intercept, otherwise known as "SSL bump".
lethargynavigator commentedon Mar 11, 2020
Ok, I was able to duplicate this off-network with the following setup:
squid configured with a basic config:
http_port 127.0.0.1:3128
http_access allow all
code:
florimondmanca commentedon Mar 13, 2020
@lethargy-navigator Thanks for providing a code snippet, but it's still hard to reproduce. Ideally we should be able to copy/paste a bunch of code, run a Python script, and see the error. :-)
Can you, in order of priority:
verify=False, requesting over HTTPS/HTTP, and perhaps a faulty server.(FWIW, background on
eof_receivedin the asyncio docs:)
lovelydinosaur commentedon Mar 16, 2020
Indeed. One other thing too - it'd be useful to isolate this as asyncio-only (or not).
Does the issue replicate if you're using
trioinstead?lethargynavigator commentedon Mar 18, 2020
@florimondmanca
error: "returning true from eof_received() has no effect when using ssl"
Unfortunately this is not caught as an exception so I don't have any details on the module or line number. It just prints to the console while my script is running.
This only affects asyncio when a proxy is used. I could not get the error to print when using trio.
Please see the following code which should allow you to easily reproduce this. This includes 100 randomly selected hosts from att.com.
florimondmanca commentedon Mar 25, 2020
Unfortunately I don't have a local proxy running so I was not able to reproduce… Can you share some steps to setup such an SSL-intercepting proxy?
lethargynavigator commentedon Mar 25, 2020
I'll use debian-based linux distro steps, but it should be similar for any linux distro.
apt install squid
mv /etc/squid/squid.conf /etc/squid/squid.conf.orig
printf 'http_port 127.0.0.1:3128\nhttp_access allow all' > /etc/squid/squid.conf
systemctl start squid
That should give you a functional squid proxy listening on 127.0.0.1:3128.
Edit: This setup does not do SSL interception, but that is not required to reproduce the issue.
10 remaining items
florimondmanca commentedon Dec 7, 2020
@amitripshtos Yeah, it seems we closed this prematurely. #54 and the subsequent PR #57 were adressing the "unrelated bug" I was referring to earlier, not the original issue here. Lemme reopen.
florimondmanca commentedon Dec 7, 2020
I've marked this as
externalbecause I believe this should be treated as a CPython "bug".See:
https://github.com/python/cpython/blob/0ef96c2b2a291c9d2d9c0ba42bbc1900a21e65f3/Lib/asyncio/streams.py#L269-L278
The code there uses a
._over_sslflag to returnFalsein the SSL case, which should prevent the warning from firing, but it does. So maybe that flag is incorrectly set?I don't think there's actually anything we can do at the HTTPX / HTTPCore level. There's a workaround above, and if this is causing too much trouble I'd recommend filing a ticket to CPython and helping solve the issue over there.
So… I'll actually close this back as "external". :-)
florimondmanca commentedon Dec 7, 2020
Woops, okay, let me go through this slowly because I think it's actually on us…
There are 4 things at play here:
StreamReaderProtocol: it's got a._over_sslflag. It'sFalseinitially, then set to "does the transport have ansslcontext?" when.connection_made()is called. https://github.com/python/cpython/blob/0ef96c2b2a291c9d2d9c0ba42bbc1900a21e65f3/Lib/asyncio/streams.py#L236SSLProtocol: it optionally calls.connection_made()on the protocol it wraps after the handshake completes.loop.start_tls: it creates aSSLProtocolwrapping the current transport protocol, but does not instruct it to call.connection_made()on the current protocol as percall_connection_made=False(since I guess asyncio assumes that protocol is "already running"). https://github.com/python/cpython/blob/0ef96c2b2a291c9d2d9c0ba42bbc1900a21e65f3/Lib/asyncio/base_events.py#L1215-L1219.start_tls()wrapper, which instantiates aStreamReaderProtocol, does not call.connection_made()on it, then passes that to asyncio'sstart_tls().So in the end, the
StreamReaderProtocol's.connection_made()doesn't get called, so_over_sslisn't set, and so the warning is logged…So, how do we fix this?
To fix this, I think we might need to modify our
.start_tls()wrapper so it uses the currently running protocol, as follows?Or maybe something else…
remi-debette commentedon Jan 11, 2021
Hi @florimondmanca, thanks for the investigation and the fix.
I understand that the fix is not released as long as encode/httpcore#251 is not merged.
Do you know when it would be available?
florimondmanca commentedon Jan 11, 2021
@remi-debette Ah, thanks for following up. Indeed I had let the release slip through as I didn't get a review of the changelog there.
Anyone can issue release PRs to HTTPCore, so if you're up for it you could either create a new one based on encode/httpcore#251 (if new PRs got merged to HTTPCore in the meantime), or just review the existing one in case it's up to date. :-) When we're ready I'd just need to merge and release from GitHub UI, but the rest can be contributor driven.
https://www.encode.io/httpcore/contributing/