Bug #40231 | GetDefaultCollation Thread sync issue | ||
---|---|---|---|
Submitted: | 22 Oct 2008 7:32 | Modified: | 13 Nov 2008 9:16 |
Reporter: | Christos Pavlides | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | Connector / NET | Severity: | S3 (Non-critical) |
Version: | 5.3.0.0 | OS: | Windows |
Assigned to: | Reggie Burnett | CPU Architecture: | Any |
Tags: | GetDefaultCollation |
[22 Oct 2008 7:32]
Christos Pavlides
[6 Nov 2008 9:08]
Sean Kinsey
This is also present in 5.2.3. The severity should be upped as this keeps this version of the connector from being usable in applications with a high degree of concurrency. I have not seens this problem in prior versions but it has started showing up after upgrading the connector to 5.2.3.
[7 Nov 2008 19:17]
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/58225
[7 Nov 2008 19:18]
Reggie Burnett
fixed in 5.2.4+
[10 Nov 2008 14:50]
Tony Bedford
An entry was added to the 5.2.4 changelog: GetDefaultCollation and GetMaxLength were not thread safe. These functions called the database to get a set of parameters and cached them in two static dictionaries in the function InitCollections. However, if many threads called them they would try to insert the same keys in the collections resulting in duplicate key exceptions.
[11 Nov 2008 22:03]
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/58505
[12 Nov 2008 7:03]
Christos Pavlides
Thanks for the fix. but I cannot see the changes in the trunk. Do you know when the changes will be merged?
[12 Nov 2008 18:55]
Reggie Burnett
merged to trunk this morning
[13 Nov 2008 9:16]
Christos Pavlides
Hi Reggie, the last commit has a bug. Basically you are trying to lock the defaultCollations collection but it is null, therefore an exception is thrown. To fix this I used a similar method as the one I described initially. Basically I created a static object and I initialized it. Then I use that object to lock. This way you are always locking the same object which is guaranteed to be not null. internal static string GetDefaultCollation(string charset, MySqlConnection connection) { lock (lockDefaultCollations) { if (defaultCollations == null) InitCollections(connection); } if (!defaultCollations.ContainsKey(charset)) return null; return defaultCollations[charset]; } internal static int GetMaxLength(string charset, MySqlConnection connection) { // we lock on defaultCollations here too so GetDefaultCollation // is on the same lock as us. lock (lockDefaultCollations) { if (maxLengths == null) InitCollections(connection); } if (!maxLengths.ContainsKey(charset)) return 1; return maxLengths[charset]; }
[13 Nov 2008 12:50]
Reggie Burnett
Christos Yes, I found that in a round of testing after the commit and committed a fix but that fix has not yet been merged to trunk.