Get the App
SLTechnology News&Howtos  ›  Network Security  › 

How to analyze the failure caused by pymysql non-thread safety

Shulou Source: shulou.com Published: 2022-05-31 21:49:12 09月15日 Update

Today, I will talk to you about how to analyze the failure caused by pymysql non-thread safety. Many people may not know much about it. In order to let everyone know more, Xiaobian summarized the following contents for everyone. I hope everyone can gain something according to this article.

mysqldb This Python driver only supports Python 2 .

Go to Python 3. It's unusable.

Enable pymysql for this driver.

After putting into production, some problems were discovered.

In using larger-scale for id in [list]:

db.query (xxxxxxxxx)

Query database, there are some strange network connection level error.

The header byte of the datagram is in the wrong format.

No error is reported if only a single query is executed.

After investigation, it was found that this is a bug or defect of pymysql.

PYmysql is not thread safe. Thanks to our own component dba module.

Wrapper for database queries.

Causing in some cases. Python code optimization module.

For code optimization, there is a parallel situation.

That is, another thread starts and reads data from the same database handle when the previous sql query did not return.

This causes the format of the datagram to be incorrect.

Improvement programme:

1. Add thread locks to database connections.

Each query is locked. Unlocking codes are also added to exception handling.

2. Replace the official mysql-connector-python driver provided for mysql.com. No problems found at this time.

After reading the above, do you have any further understanding of how to analyze pymysql non-thread-safe failures? If you still want to know more knowledge or related content, please pay attention to the industry information channel, thank you for your support.

Tags: Data thread query situation database security code content driver fault analysis format module error problem support large single handle just Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft OPPO Reno Linux Docker MySQL