Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

SqlMapper.AddTypeHandler not thread safe #1815

Copy link
Copy link
@StephanMoeller

Description

@StephanMoeller
Issue body actions

SqlMapper.SetTypeMap is thread safe. This is achievede by:

lock (_typeMaps)
{
...
}

But SqlMapper.AddTypeHandler is not thread safe.

I think it would be valuable to make AddTypehandler thread safe as it enables different data access to be self contained instead of having a central place for registering all custom types.

Scenario:

Using 3rd party package A and another third party package B.
These both use Dapper. No problem, it is the same version.

These two packages each register some custom type handlers lazily, the first time they need them.

In AddTypeHandler there is no locking, the flow is as follows:

...
var snapshot = typeHandlers;
... // <= In this time span, multiple simultanious calls will trigger lost updates.
typeHandlers = newCopy;

I felt this the hard way in production yesterday.

Reactions are currently unavailable

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.