Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3.7 ValueError: attempt to connect already-connected SSLSocket! #1549

Closed
dwintergruen opened this issue Jul 17, 2018 · 14 comments
Closed
Labels

Comments

@dwintergruen
Copy link

Try to establish a producer with:

(python3.7 Mac OS high Sierra)

producer = KafkaProducer(bootstrap_servers='SERVER:9093', ssl_password="XXXXX",
ssl_cafile="/etc/kafka_clients/ca-cert", security_protocol="SSL",
ssl_certfile="/etc/kafka_clients/cert-signed",
ssl_keyfile="/etc/kafka_clients/private-key")

always get:

File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kafka/producer/kafka.py", line 362, in init
**self.config)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kafka/client_async.py", line 214, in init
self._bootstrap(collect_hosts(self.config['bootstrap_servers']))
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kafka/client_async.py", line 245, in _bootstrap
if not bootstrap.connect_blocking():
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kafka/conn.py", line 301, in connect_blocking
self.connect()
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/kafka/conn.py", line 354, in connect
ret = self._sock.connect_ex(self._sock_addr)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1146, in connect_ex
return self._real_connect(addr, True)
File "/usr/local/Cellar/python/3.7.0/Frameworks/Python.framework/Versions/3.7/lib/python3.7/ssl.py", line 1118, in _real_connect
raise ValueError("attempt to connect already-connected SSLSocket!")
ValueError: attempt to connect already-connected SSLSocket!

@freeyoung
Copy link

I'm getting exactly the same exception. Python 3.6 & 3.5 work prefectly.

@bunnyc1986
Copy link

bunnyc1986 commented Aug 10, 2018

I am getting the same error. Python 3.7 as well.

May be related to this change: https://github.com/python/cpython/pull/5252/files#diff-c49248c7181161e24048bec5e35ba953R1108

@apoclyps
Copy link

apoclyps commented Aug 10, 2018

I've encountered the same problem described above whilst upgrading to python:3.7-alpine. I've created a test case which should allow easy reproduction of the issue.

I've attempted to experiment with different kafka-python versions but found the issue described above limited to 1.4.3. 1.4.2 produces a different issue, outlined separately at the bottom of issue

jsargiot added a commit to scrapinghub/kafka-consumer-group-exporter that referenced this issue Aug 24, 2018
@matthieugouel
Copy link

Hello,

As @bunnyc1986 pointed out, it has to do with a modification of the SSL module of CPython. I tried to remove the self._sslobj is not None of the line 1108 and it worked perfectly, but I guess the underlaying issue comes from kafka-python which may try to do a connection with the same socket multiple times.

It's a little annoying because it prevents us to upgrade python to 3.7 just for that tiny issue ...

@richtera
Copy link

Any news on this?

@jeffwidman
Copy link
Collaborator

A PR would be welcome from someone who can test on permutations of SSL enabled / disabled for python 2.7, 3.6, and 3.7.

@jeffwidman jeffwidman added the bug label Oct 29, 2018
BaardBouvet added a commit to sesam-community/kafka that referenced this issue Nov 2, 2018
@T-baby
Copy link

T-baby commented Nov 14, 2018

When can python-kafka fix this problem?

@dpkp
Copy link
Owner

dpkp commented Nov 14, 2018 via email

@T-baby
Copy link

T-baby commented Nov 22, 2018

Come and see it every day. When can python-kafka fix this problem?

@dpkp
Copy link
Owner

dpkp commented Nov 22, 2018 via email

@dpkp dpkp changed the title ValueError: attempt to connect already-connected SSLSocket! Python3.7 ValueError: attempt to connect already-connected SSLSocket! Nov 23, 2018
seanthegeek pushed a commit to seanthegeek/kafka-python that referenced this issue Nov 27, 2018
Fix SSL connection testing in Python 3.7
@seanthegeek
Copy link

@dpkp Here's that PR :)

melor pushed a commit to aiven/kafka-python that referenced this issue Nov 30, 2018
Fix SSL connection testing in Python 3.7
toivonen1979 pushed a commit to toivonen1979/P1 that referenced this issue Dec 3, 2018
ValueError: attempt to connect already-connected SSLSocket!
dpkp/kafka-python#1549
@silentben
Copy link

@dpkp Looks like both @seanthegeek and I have submitted pull requests to fix this. Anything you're looking for before merging one or the other?

@jeffwidman
Copy link
Collaborator

Fixed by #1669

@slyons
Copy link

slyons commented Mar 12, 2019

This is still an issue in the current release. Any chances of a newer release?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests