SCM

[#1010996] Not correct double checked locking in CreateAndLoadInitialTypesMapping

View Trackers | Bugs | Download .csv | Monitor

Date:
2011-02-22 10:36
Priority:
3
State:
Open
Submitted by:
Alex A Ermoshenko (erax)
Assigned to:
Nobody (None)
Npgsql Version:
2.0.11
Category:
Group:
Resolution:
None
Summary:
Not correct double checked locking in CreateAndLoadInitialTypesMapping

Detailed description
Our server could not start normally, when hаs big queue of requests from users. We are healed this by making pre-heating (warming up) the server - creating multiple connections to the database before processing requests.

I read you comments on this method, you wrote about "... problem with temporarily having two copies of the same mapping", in our situation created 14 NpgsqlBackendTypeMapping objects :-)


You variant of code:
CreateAndLoadInitialTypesMapping
{
if(mapping = TryGetLoadedMapping())
return mapping;
newMapping = CreateAndLoadMapping();
if(mapping = TryGetLoadedMapping())
return mapping;
lock(mappings)
{
if(mapping = TryGetLoadedMapping())
return mapping;
mappings.Add(newMapping);
}
}
Proposed variant:
CreateAndLoadInitialTypesMapping
{
if(mapping = TryGetLoadedMapping())
return mapping;
lock(mappings)
{
if(mapping = TryGetLoadedMapping())
return mapping;
newMapping = CreateAndLoadMapping();
mappings.Add(newMapping);
}
}

Followup

Message
Date: 2011-02-22 10:55
Sender: Alex A Ermoshenko

i forgot returns

mappings.Add(newMapping);
return newMapping;

Attached Files:

Changes:

No Changes Have Been Made to This Item

Powered By FusionForge