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

SSL wrapped socket is not set to non-blocking #2

Closed
jpwsutton opened this issue Feb 4, 2016 · 0 comments
Closed

SSL wrapped socket is not set to non-blocking #2

jpwsutton opened this issue Feb 4, 2016 · 0 comments
Milestone

Comments

@jpwsutton
Copy link

migrated from Bugzilla #465625
status UNCONFIRMED severity normal in component MQTT-Python for 1.1
Reported in version 1.1 on platform PC
Assigned to: Roger Light

Original attachment names and IDs:

On 2015-04-27 16:13:31 -0400, Jeff Jasper wrote:

When using SSL enabled Paho and publishing a large number (~ 1000) of messages in rapid succession I noticed a behavior where 50-100 messages would be sent and then a period of 1 minute would elapse before the remaining messages were sent. I tracked the delay down to the ssl.read(1) (line 1405) method in _packet_read. It appears that the socket may be getting disconnected causing the read to block for a minute before returning an empty byte.

I noticed that the ssl wrapped socket (generated in the reconnect method) is not explicitly set to non-blocking like it is for a non-SSL socket. After setting the ssl wrapped socket to non-blocking the delay when publishing a large burst of messages appears to be gone. I guess this isn't necessarily a bug, but rather a performance issue.

On 2015-05-23 17:21:11 -0400, Roger Light wrote:

Hi Jeff,

Thanks for this, but I'm a bit confused. The socket gets set to be non-blocking around line 756, regardless of whether it is SSL or not. The ssl.wrap_socket() call is blocking, but everything afterwards should be non-blocking.

On 2016-01-12 05:21:16 -0500, Pierre Fersing wrote:

Created attachment 259120
script to test SSL blocking status

I confirm what Jeff seen, SSL is blocking... but only with Python 3 :(

Python 2 works well, but not Python 3 (tested 2.7.10 and 3.4.3)

With Python 2 calling setblocking(0) on either raw-socket or ssl-socket is enough.

With Python 3 calling setblocking(0) on raw-socket change nothing on ssl-socket. We need to call setblocking(0) on ssl-socket to make ssl socket non-blocking.

I've attached a basic script that I used to test the blocking status of ssl socket.

@ralight ralight added this to the 1.2 milestone Jun 1, 2016
ralight added a commit that referenced this issue Jun 1, 2016
Thanks to Jeff Jasper and Pierre Fersing.

Change-Id: I1662f0d57839bce64137c798f427fc7cdb22bc34
@ralight ralight closed this as completed Jun 1, 2016
jbarlow-mcafee added a commit to jbarlow-mcafee/opendxl-client-python that referenced this issue Mar 2, 2018
This fix makes the setblocking() call on the socket in a manner which is
compatible with Python 3.

See eclipse-paho/paho.mqtt.python#2 and
eclipse-paho/paho.mqtt.python@18266e8
for more details.
jbarlow-mcafee added a commit to jbarlow-mcafee/opendxl-client-python that referenced this issue Mar 6, 2018
This fix makes the setblocking() call on the socket in a manner which is
compatible with Python 3.

See eclipse-paho/paho.mqtt.python#2 and
eclipse-paho/paho.mqtt.python@18266e8
for more details.
jbarlow-mcafee added a commit to jbarlow-mcafee/opendxl-client-python that referenced this issue Mar 7, 2018
This fix makes the setblocking() call on the socket in a manner which is
compatible with Python 3.

See eclipse-paho/paho.mqtt.python#2 and
eclipse-paho/paho.mqtt.python@18266e8
for more details.
jbarlow-mcafee added a commit to jbarlow-mcafee/opendxl-client-python that referenced this issue Apr 12, 2018
This fix makes the setblocking() call on the socket in a manner which is
compatible with Python 3.

See eclipse-paho/paho.mqtt.python#2 and
eclipse-paho/paho.mqtt.python@18266e8
for more details.
mikewadsten added a commit to digidotcom/paho.mqtt.python that referenced this issue Aug 15, 2023
This commit is the result of squashing several intermediate commits.
The individual commit messages were as follows:

Commit message eclipse-paho#1
-----------------

Roll back changes from commit 4910b78.

The commit referenced above removed uses of `socket.error`,
preferring instead to use the Python 3 builtin error types.
This causes various subtle issues with Python 2.7.

In this "revert", I have opted to have the compatibility
`BlockingIOError` be defined as a subclass of IOError, rather than
simply a name alias, because at least within this file, at least,
all uses where we need to check for it. Since `socket.error` is a
subclass of IOError, making `BlockingIOError` a name alias would make
the code more confusing, since it may not be obvious to the reader that
this is the case.

Commit message eclipse-paho#2
-----------------

Bump __version__ to reflect Digi patches have been applied

Commit message eclipse-paho#3
-----------------

Add _on_pre_connect default value of None

Otherwise a client using `.connect_async` will error out.

Commit message eclipse-paho#4
-----------------

Catch and handle socket.error on reconnect calls

Commit message eclipse-paho#5
-----------------

Use select.poll instead of select.select

select.select only works if the fileno values of the given objects
are <1024. In an application that uses or creates hundreds of file
descriptors, one can very easily end up in a situation where the socket
file descriptor is beyond that.

A typical Linux system will have the open file limit for the user set
to 1024, so this generally doesn't happen. But with this change in
place, Paho will function correctly if it does.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants