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

connection.settimeout not work #1119

Closed
jerryyyq opened this issue Apr 27, 2022 · 2 comments
Closed

connection.settimeout not work #1119

jerryyyq opened this issue Apr 27, 2022 · 2 comments

Comments

@jerryyyq
Copy link

pyOpenSSL version is: 22.0.0
openssl version is: 1.1.1j
OS: ubuntu 18.04
Python 3.6.9

when I called "connection.setblocking(True) ", the time out is invalid:

import OpenSSL
import socket
ctx = OpenSSL.SSL.Context(OpenSSL.SSL.TLS_CLIENT_METHOD)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

connection = OpenSSL.SSL.Connection(ctx, s)
connection.set_tlsext_host_name(b"www.daiyue.gov.cn")

connection.connect(("www.daiyue.gov.cn", 443))
connection.settimeout(3)

connection.setblocking(True)

connection.do_handshake()

^CTraceback (most recent call last):
File "", line 1, in
File "/home/yangyuqi/.local/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1990, in do_handshake
result = _lib.SSL_do_handshake(self._ssl)
KeyboardInterrupt

when I not called "connection.setblocking(True) ", the connection.do_handshake() is abnormal

ctx = OpenSSL.SSL.Context(OpenSSL.SSL.TLS_CLIENT_METHOD)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
connection = OpenSSL.SSL.Connection(ctx, s)
connection.set_tlsext_host_name(b"www.daiyue.gov.cn")
#connection.set_connect_state()

connection.connect(("www.daiyue.gov.cn", 443))
connection.settimeout(3)

connection.do_handshake()
Traceback (most recent call last):
File "", line 1, in
File "/home/yangyuqi/.local/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1991, in do_handshake
self._raise_ssl_error(self._ssl, result)
File "/home/yangyuqi/.local/lib/python3.6/site-packages/OpenSSL/SSL.py", line 1675, in _raise_ssl_error
raise WantReadError()
OpenSSL.SSL.WantReadError

@facutuesca
Copy link
Contributor

The reason why the timeout is not working in the first fragment of code:

import OpenSSL
import socket
ctx = OpenSSL.SSL.Context(OpenSSL.SSL.TLS_CLIENT_METHOD)
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)

connection = OpenSSL.SSL.Connection(ctx, s)
connection.set_tlsext_host_name(b"www.daiyue.gov.cn")

connection.connect(("www.daiyue.gov.cn", 443)) # script blocks here
connection.settimeout(3) # timeout is set here

connection.setblocking(True)

connection.do_handshake()

is that the script blocks on the connect() call, so the timeout is never actually set. By putting the connect() call after setting the timeout, you get the expected TimeoutError exception.

@alex I think this one can be closed

@mhils
Copy link
Member

mhils commented Oct 2, 2023

Thanks @facutuesca! 🍰

@mhils mhils closed this as completed Oct 2, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 1, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants