sessionfiddlerfiddlercore

FiddlerCore: is it safe to use Session.id as unique identifier?


I'm trying to fix someone else's code. In the original code, he uses Session.fullUrl as TKey for a ConcurrentDictionary. Everything works fine until the client sends two requests with the exactly same url at the same time, apparently that's not a usual behavior but it's not something I can change.

So I made some changes to the code, now I use a new string (Session.id.ToString()+Session.fullUrl) as TKey, and the code works. However, since the url is never used again, I wonder if I can just drop it and use only Session.id as TKey, but I'm not sure if it's safe - If the program runs long enough, will there be a new session with same Session.id?


Solution

  • Session.id values are assigned consecutively using an Int32 counter, which could be reset only using the FiddlerApplication.ResetSessionCounter() call - so yes, it's relatively safe to use this as unique key as long as you are not calling this method as part of your own customization.

    "Relative", because overflows of the counter are possible and will be silently ignored (as we internally use Interlocked.Increment), but this could probably lead to other unexpected bugs as well.