Bug #36688 SemaphoreFullException when closing application
Submitted: 13 May 2008 13:24 Modified: 22 Jul 2008 16:04
Reporter: Paul Bowden Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S2 (Serious)
Version:5.1.6 OS:Windows (XP SP2 & Vista)
Assigned to: CPU Architecture:Any
Tags: exception, Semaphore

[13 May 2008 13:24] Paul Bowden
Description:
I have just upgraded from 5.1.2 -> 5.1.6, and now when I close my application I receive a SemaphoreFullException.

System.Threading.SemaphoreFullException was unhandled
  Message="Adding the given count to the semaphore would cause it to exceed its maximum count."
  Source="System"
  StackTrace:
       at System.Threading.Semaphore.Release(Int32 releaseCount)
       at System.Threading.Semaphore.Release()
       at MySql.Data.MySqlClient.MySqlPool.RemoveConnection(Driver driver)
       at MySql.Data.MySqlClient.MySqlPoolManager.RemoveConnection(Driver driver)
       at MySql.Data.MySqlClient.Driver.Dispose(Boolean disposing)
       at MySql.Data.MySqlClient.NativeDriver.Dispose(Boolean disposing)
       at MySql.Data.MySqlClient.Driver.Close()
       at MySql.Data.MySqlClient.NativeDriver.Finalize()

I can see others complaining about this issue in bugs #30642 and #30816

How to repeat:
Uninstall previous connector, install 5.1.6. We then recompile our application and the problem will happen after shutdown (main has returned).
[14 May 2008 9:44] Claire Humphrey
I'm receiving the same exception after installing 5.1.6 this morning 14/5/2008
[15 May 2008 9:43] Tonci Grgin
Hi Paul and thanks for your report. The only relevant change I can find is:
- Fixed problem with connections staying open after being used with SqlDataSource.
   The problem was that we were not returning an enumerator for our reader with the closeReader option set to true when we were supposed to.(Bug #34460)

As there is no test case attached I will use my own from Bug#30642.
[16 May 2008 9:59] Bernardo Marques
I have just the same problem.
I'm using MySQL connector 5.1.6, Windows XP Portuguese.
MySQL server 5.0.45 running on Linux.

The problem happens whenever you create two connections.

Sample code:

using System;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace MySQLbug
{
   /// <summary>
   /// Description of MainForm.
   /// </summary>
   public partial class MainForm : Form {
      public MainForm() {
         InitializeComponent();
         DoSomething();
         DoSomething();     //again, or something else that opens a connection
      }

      private void DoSomething() {
         MySqlConnection con = null;
         MySqlCommand com = null;

         try {
            con = new MySqlConnection("Database=db; Data Source=server; User Id=uid; Password=pass");
            com = new MySqlCommand();
            com.Connection = con;
            com.Connection.Open();
         } catch (MySqlException) {
         } finally {
            if (com != null) {
               com.Dispose();
               com = null;
            }
            if (con != null) {
               try {
                  con.Close();
               } catch (MySqlException) {}
               con.Dispose();
               con = null;
            }
         }
      }
   }
}

End of sample code.

Whenever you close the form the System.Threading.SemaphoreFullException is thrown. And from my point of view both connections were properly closed.

If you just comment one of calls the exception won't be thrown.
[16 May 2008 10:26] Bernardo Marques
Just downloaded .Net connector 5.2.2 and the poblem is gone :)
[20 May 2008 18:33] Bugs System
A patch for this bug has been committed. After review, it may
be pushed to the relevant source trees for release in the next
version. You can access the patch from:

  http://lists.mysql.com/commits/46888
[20 May 2008 18:33] Reggie Burnett
Fixed in 5.1.7.  Not a bug in 5.2+
[4 Jun 2008 15:35] alphaxxx xxx
when The v5.1.7 to release ?
[5 Jun 2008 19:29] Reggie Burnett
Might be still a little bit.  So far I only have two changes for 5.1.7 and I need to get 5.2.3 and 5.3 beta out first.
[16 Jun 2008 9:09] Paul Bowden
Is it possible to give a rough timescale for the 5.1.7 release, i.e. this month, next month etc?

This will allow me to determine whether to patch 5.1.6 manually, or wait for the release.

Regards,

Paul
[17 Jun 2008 15:29] Reggie Burnett
Paul

It will likely drop the first part of next month since I won't get to it this week and I'm on vacation next week.  I would like to squeeze a few more fixes into it before it drops too.  I'm working on getting the snapshot system back up and functional which should start producing 5.1, 5.2, and 5.3 snapshots of the trees.
[7 Jul 2008 9:43] Paul Bowden
Any update on this? Also the snapshots don't appear to be up to date yet. Also checked out 5.1.6 but it has files missing...
[8 Jul 2008 14:25] Tony Bedford
An entry has been added to the 5.1.7 Changelog:

SemaphoreFullException is generated when application is closed.
[9 Jul 2008 3:46] zhou shaoping
[16 May 12:26] Bernardo Marques  

is right, thanks for you help!
[15 Jul 2008 13:40] Jon Swain
Any idea on when version 5.1.7 will be released, or when the snapshots will be back up?
[22 Jul 2008 13:41] Ralph Jansen
I have the same problem. 
When is 5.1.7 coming out?
[22 Jul 2008 13:59] mick smith
Please can you tell us when 5.1.7 will be released with this bug fixed. It is causing me serious problems
[22 Jul 2008 14:03] Tonci Grgin
Guys, sorry, I am not ignoring you but I just don't know... There is a whole rigorous process running in background before connector is released. Maybe Reggie knows more.
[22 Jul 2008 14:16] Reggie Burnett
Guys

I hear you that you are waiting for 5.1.7.  I've been very busy with several other projects but also getting as many bug fixes as I can into 5.1.7 for the release.  I am hoping to do a formal release this week.

I don't want to seem insensitive but we are an open source shop and the full sources for 5.1.7 are available to you today.  Just go to http://svn.mysql.com and go into the area for Connector/net and you'll see how to hook up your SVN client to our public repo.  I know it's not a replacement for an official binary but if someone *has* to have it today then just grab the source and build.  It should build with VS 2005 and 2008 with no problem.
[22 Jul 2008 16:04] Paul Bowden
Hi Reggie,

I have downloaded the 5.1 branch, installed the Vistual Studio 2005 SDK, modified MySql.VisualStudio.csproj to set the path for Microsoft.VsSDK.targets, however when I try to build the solution I get some errors (see below). Do I need to install anything else?

Error	1	Cryptographic failure while signing assembly 'C:\MySQL\5.1\Driver\obj\Debug\MySql.Data.dll' -- 'The key container name 'ConnectorNet' does not exist'	MySql.Data

Error	4	The name 'TryGetValue' does not exist in the current context	C:\MySQL\5.1\Driver\Source\MySqlConnectionStringBuilder.cs	1182	13	MySql.Data.CF

Error	5	The best overloaded method match for 'System.Text.StringBuilder.AppendFormat(System.IFormatProvider, string, params object[])' has some invalid arguments	C:\MySQL\5.1\Driver\Source\MySqlConnectionStringBuilder.cs	1191	17	MySql.Data.CF

Error	6	Argument '1': cannot convert from 'string' to 'System.IFormatProvider'	C:\MySQL\5.1\Driver\Source\MySqlConnectionStringBuilder.cs	1191	48	MySql.Data.CF

Error	7	Argument '3': cannot convert from 'object' to 'object[]'	C:\MySQL\5.1\Driver\Source\MySqlConnectionStringBuilder.cs	1191	69	MySql.Data.CF
[22 Jul 2008 16:28] Reggie Burnett
Paul

Just disable the mysql.data.cf project as that is for the compact framework (I'm working on that fix).  Also, you can either create a new signing key or just comment out that line from the assemblyinfo.cs file.
[29 Jul 2008 1:20] kiku apple
//[16 May 12:26] Bernardo Marques
//Just downloaded .Net connector 5.2.2 and the poblem is gone :)

wow, thanks.. it's working now
[30 Jul 2008 23:13] Philip Hofer
I have 5.2.2 and this is still a problem for me.
[30 Jul 2008 23:30] Philip Hofer
"   at System.Threading.Semaphore.Release(Int32 releaseCount)\r\n   at System.Threading.Semaphore.Release()\r\n   at MySql.Data.MySqlClient.MySqlPool.RemoveConnection(Driver driver)\r\n   at MySql.Data.MySqlClient.MySqlPoolManager.RemoveConnection(Driver driver)\r\n   at MySql.Data.MySqlClient.Driver.Dispose(Boolean disposing)\r\n   at MySql.Data.MySqlClient.NativeDriver.Dispose(Boolean disposing)\r\n   at MySql.Data.MySqlClient.Driver.Close()\r\n   at MySql.Data.MySqlClient.NativeDriver.Finalize()"

...
[13 Aug 2008 20:52] Gert Brigsted
Any updates on when 5.1.7 is being released?
[17 Sep 2008 5:48] jacky chong
Please download connector 5.1.7 to solve this problem.
[3 Mar 2010 14:00] Usman Ali
Two step to solve System.Threading.Semaphore.Release Issue

1. Install Latest mySQL Connector 6.0 or later

2.Set pooling=false; in the connection string.

For Example :

ConnectionStringObject="server=localhost;user id=root;password=usman;database=uts1;persist security info=True;pooling=false;"

_________________

www.ashscholar.com
[18 Jun 2010 20:30] Phil W
YES!!!!

many thanks to Usman Ali.

Phil