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.SSLError: [SSL: BAD_LENGTH] bad length (_ssl.c:2423) #1992

Open
joan-mido-qa opened this issue Sep 5, 2023 · 0 comments
Open

ssl.SSLError: [SSL: BAD_LENGTH] bad length (_ssl.c:2423) #1992

joan-mido-qa opened this issue Sep 5, 2023 · 0 comments

Comments

@joan-mido-qa
Copy link

Environment

  • gevent version: From PIP
  • Python version: 3.10
  • Operating System: Ubuntu 23.04

Description:

We use Locust and Paho-MQTT to spawn multiple clients to load-test an IoT application. It works as expected for ~60Kb payloads, but we had problems sending heavier messages. The error rises at ~6000 requests.

  • We could not reproduce the error using the Client without gevent
  • We could not reproduce the error using a non-TLS connection

Do you know what's going on? Thanks in advance!

Exception in thread Thread-1 (_thread_main):
Traceback (most recent call last):
  File "/usr/lib/python3.11/threading.py", line 1038, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.11/threading.py", line 975, in run
    self._target(*self._args, **self._kwargs)
  File "venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 3591, in _thread_main
    self.loop_forever(retry_first_connection=True)
  File "venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1756, in loop_forever
    rc = self._loop(timeout)
         ^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1181, in _loop
    rc = self.loop_write()
         ^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 1577, in loop_write
    rc = self._packet_write()
         ^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 2464, in _packet_write
    write_length = self._sock_send(
                   ^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/paho/mqtt/client.py", line 649, in _sock_send
    return self._sock.send(buf)
           ^^^^^^^^^^^^^^^^^^^^
  File "venv/lib/python3.11/site-packages/gevent/ssl.py", line 508, in send
    return self._sslobj.write(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^
ssl.SSLError: [SSL: BAD_LENGTH] bad length (_ssl.c:2423)

What I've run:

Reproducible example using mosquitto test broker: https://test.mosquitto.org

from gevent import monkey, sleep

monkey.patch_all()

import json
import ssl
import paho.mqtt.client as mqtt

mqttc = mqtt.Client()

tls_context = ssl.SSLContext(ssl.PROTOCOL_TLS_CLIENT)
tls_context.load_cert_chain("client.crt", "client.key")
tls_context.load_verify_locations("mosquitto.org.crt")

mqttc.tls_set_context(tls_context)

mqttc.connect("test.mosquitto.org", 8884, 60)

mqttc.loop_start()

for i in range(0, 1000000):
    info = mqttc.publish("test", json.dumps({"message": "1" * 200000}).encode(), qos=0)
    sleep(0.01)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant