Are you sure of your finding? There have been reports that under heavy load conditions SQL Server's new guid function will yield duplicates, but this is this first report I have heard of the framework giving such a problem.
Click "Mark as Answer" on the post that helped you.
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
Well I just checked connect.microsoft.com and there are no active issues on NewGuid. But perhaps you or someone knows steps to reproduce such a problem?
James Still
SquareWidget LLC
Handcrafted .NET Software
http://www.squarewidget.com
No, I can't say for sure that the problem is duplicate GUID but currently I have only one explanation of the issue I have here and this explanation is based on assumption that GUID could be duplicated:
- I use GUID as the key for some session values stored in Cache, and I have GUID itself stored in Session[...] using constant session value key name....
If Guid would be always unique I would never have "sessions overlapping issue" - when two different sessions, initiated from two different PCs, with rather different IP addresses, located in different geographical points get somewhow the same Session.SessionId,
which I do use as unique identifier to store page hits trace in MS SQL db - and I see from this trace that the same Session.SessionId is obtained and then stored from PCs with different IP-addresses....I can be wrong with my assumptions...
I will try to add more tracing...
The bug could be of course somewhere else in my own code but the fact is that in 90%-95% of cases everything works well - therefore it should be something with thread-safety violation?....
The problem could be with my own coding of course but this is a rather large application and it works well most of the time IOW it's not easy to find out currently what is wrong with it....
In my opinion, there is no possibility that the .net framework generates the same GUID within the same server. And you don't need the lock statement. And if you use a x86 server it's impossible.
Maybe the "Duplicate GUID in Sql Server" story was the result of mergeing data in a table which were created in different servers (or at least the guid's were genereated on different servers).
This however was not the report I saw about 6 months ago.
Click "Mark as Answer" on the post that helped you.
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
I'm running into this issue using the .Net NewGUID() function within an SSIS script transformation component. This issue occured repeatedly with each execution of the SSIS package. Then, I found the one that thing that seemed to be causing the problem.
My system was running very low on resources. My machine was slowing down steadily. Eventually, as the process slowed to almost a crawl, I would receive a duplicate GUID error. The GUID was the primary key in the table and didn't allow duplicates generating
a primary key violation. Once I resolved the memory/resource issued, the problem disappeared completely. It never happened again.
Thank you Michael and all who answered on this thread subject issue!
I can't say for sure now that the problem was/is in NewGuid(...) duplicates.
I did add some more tracing, and I did make other fixes (locking) - so far the issue didn't happen again.
I'm currently working on another project due very soon, but I keep watching the subject project, which is runnng in live mode, when I will have more time, or if the subject issue will start appearing often, I will try to find out the real cause of the problem.
I will then report/post here the results of my findings.
ShamilMS
Member
97 Points
46 Posts
Duplicate GUID generated because of absense of lock { ... } statement?
Jan 30, 2008 06:07 PM|LINK
Hi All,
Please have a look at this code:
public sealed class Test
{
// mnemonic constant
public const string USER_KEY_ATTRS_KEY_NAME = "key_name";
// Stores user attributes in Cache using indirect autogenerated key
public static void StoreUserAttrs(string attr1, string attr2, string attr3)
{
// get key
string key = System.Guid.NewGuid().ToString();
// put key in Session
HttpContext.Current.Session[USER_KEY_ATTRS_KEY_NAME] = key;
// concatenate attributes
string attrs = attr1 + "+" + attr2 + "+" + attr3;
// put attributes in Cache
HttpContext.Current.Cache[key] = attrs;
}
}
Is there any chance that the bold code line above returns the same GUID for two (or more) concurrent ASP.NET Sessions?
If the code above isn't thread safe then this code below should 100% fix the issue?
public sealed class Test
{
private static object _locker = new object();
// mnemonic constant
public const string USER_KEY_ATTRS_KEY_NAME = "key_name";
// Stores user attributes in Cache using indirect autogenerated key
public static void StoreUserAttrs(string attr1, string attr2, string attr3)
{
// get key
string key = String.Empty;
lock (_locker)
{
key = System.Guid.NewGuid().ToString();
}
// put key in Session
HttpContext.Current.Session[USER_KEY_ATTRS_KEY_NAME] = key;
// concatenate attributes
string attrs = attr1 + "+" + attr2 + "+" + attr3;
// put attributes in Cache
HttpContext.Current.Cache[key] = attrs;
}
}
Thank you.
SS
jamesstill
Member
612 Points
82 Posts
Re: Duplicate GUID generated because of absense of lock { ... } statement?
Jan 30, 2008 08:46 PM|LINK
SquareWidget LLC
Handcrafted .NET Software
http://www.squarewidget.com
TATWORTH
All-Star
72405 Points
14018 Posts
MVP
Re: Duplicate GUID generated because of absense of lock { ... } statement?
Jan 30, 2008 08:58 PM|LINK
Are you sure of your finding? There have been reports that under heavy load conditions SQL Server's new guid function will yield duplicates, but this is this first report I have heard of the framework giving such a problem.
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
jamesstill
Member
612 Points
82 Posts
Re: Duplicate GUID generated because of absense of lock { ... } statement?
Jan 30, 2008 09:19 PM|LINK
SquareWidget LLC
Handcrafted .NET Software
http://www.squarewidget.com
ShamilMS
Member
97 Points
46 Posts
Re: Duplicate GUID generated because of absense of lock { ... } statement?
Jan 30, 2008 09:44 PM|LINK
No, I can't say for sure that the problem is duplicate GUID but currently I have only one explanation of the issue I have here and this explanation is based on assumption that GUID could be duplicated:
- I use GUID as the key for some session values stored in Cache, and I have GUID itself stored in Session[...] using constant session value key name....
If Guid would be always unique I would never have "sessions overlapping issue" - when two different sessions, initiated from two different PCs, with rather different IP addresses, located in different geographical points get somewhow the same Session.SessionId, which I do use as unique identifier to store page hits trace in MS SQL db - and I see from this trace that the same Session.SessionId is obtained and then stored from PCs with different IP-addresses....I can be wrong with my assumptions...
I will try to add more tracing...
The bug could be of course somewhere else in my own code but the fact is that in 90%-95% of cases everything works well - therefore it should be something with thread-safety violation?....
Thank you.
SS
ShamilMS
Member
97 Points
46 Posts
Re: Duplicate GUID generated because of absense of lock { ... } statement?
Jan 30, 2008 09:47 PM|LINK
No, James, I do not know these steps (yet).
The problem could be with my own coding of course but this is a rather large application and it works well most of the time IOW it's not easy to find out currently what is wrong with it....
SS
hveseli
Member
273 Points
74 Posts
Re: Duplicate GUID generated because of absense of lock { ... } statement?
Jan 31, 2008 11:04 AM|LINK
In my opinion, there is no possibility that the .net framework generates the same GUID within the same server. And you don't need the lock statement. And if you use a x86 server it's impossible.
See also the very interesting articles by vance morrison http://msdn.microsoft.com/msdnmag/find/?type=Au&phrase=Vance%20Morrison&words=exact
Maybe the "Duplicate GUID in Sql Server" story was the result of mergeing data in a table which were created in different servers (or at least the guid's were genereated on different servers).
Greetings,
hv
TATWORTH
All-Star
72405 Points
14018 Posts
MVP
Re: Duplicate GUID generated because of absense of lock { ... } statement?
Jan 31, 2008 12:33 PM|LINK
>Maybe the "Duplicate GUID in Sql Server" story was the result of merging data
Duplicate Guid's were reported in SQL Server CE Refresh Fixes GUID Generation Problems at http://support.microsoft.com/kb/q286357/
This however was not the report I saw about 6 months ago.
This earns you a point and marks your thread as Resolved so we will all know you have been helped.
FAQ on the correct forum http://forums.asp.net/p/1337412/2699239.aspx#2699239
pyelor
Member
2 Points
1 Post
Re: Duplicate GUID generated because of absense of lock { ... } statement?
Feb 01, 2008 09:03 PM|LINK
I'm running into this issue using the .Net NewGUID() function within an SSIS script transformation component. This issue occured repeatedly with each execution of the SSIS package. Then, I found the one that thing that seemed to be causing the problem. My system was running very low on resources. My machine was slowing down steadily. Eventually, as the process slowed to almost a crawl, I would receive a duplicate GUID error. The GUID was the primary key in the table and didn't allow duplicates generating a primary key violation. Once I resolved the memory/resource issued, the problem disappeared completely. It never happened again.
Hope this helps.
Michael
ShamilMS
Member
97 Points
46 Posts
Re: Duplicate GUID generated because of absense of lock { ... } statement?
Feb 01, 2008 09:14 PM|LINK
Thank you Michael and all who answered on this thread subject issue!
I can't say for sure now that the problem was/is in NewGuid(...) duplicates.
I did add some more tracing, and I did make other fixes (locking) - so far the issue didn't happen again.
I'm currently working on another project due very soon, but I keep watching the subject project, which is runnng in live mode, when I will have more time, or if the subject issue will start appearing often, I will try to find out the real cause of the problem.
I will then report/post here the results of my findings.
Thank you.
SS