MySQLConnector/Net handle Leakage

Source: Internet
Author: User
In the MySQL5.5 environment, the ConnectorNet version is 6.8.3.0, and the memory and handle are leaked when a connection exception is opened. I wrote a small program to test it: privatevoidHandleLeak () {DbConnection

In the MySQL5.5 environment, the Connector/Net version is 6.8.3.0, and the memory and handle are leaked when a connection exception is opened. I wrote a small program to test it: privatevoidHandleLeak () {DbConnection

In the MySQL 5.5 environment, the Connector/Net version is 6.8.3.0, and the memory and handle are leaked when a connection exception is opened. Write a small program to test it:


Private void HandleLeak () {DbConnection conn = null; while (true) {try {// the server can be connected, but the password is incorrect, when opening, predictionconn = new MySqlConnection ("Server = localhost; Database = test; Uid = username; Pwd = wrong password"); conn. open ();} catch {// clear conn. close (); conn. dispose (); conn = null; Console. writeLine ("Connect Error");} finally {Thread. sleep (1000 );}}}


In the task manager, we observe that the number of handles has been increasing, but the same code is no problem if changed to SqlServer. After using ProcessXp, the process occupies a large number of TCP connections and is in the CLOSE_WAIT status. The connection between the Process and the server is not properly closed, using netstat-ano | findstr "3306", you can see that mysqld.exe (PID: 1900) has a large number of connections in the FIN_WAIT_2 state.


In terms of status, it seems that after the login fails, the server actively disconnects, but the client does not close the tcp connection correctly. For details, refer to the source code of Connector, but it is not available now, wait for a while. Some experts know the problem and leave a comment.


In addition, if GC. Collect () is executed, the handle will not be leaked.



This article is from the "Rabbit nest" blog. Please keep this source

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.