File tree 2 files changed +23
-13
lines changed
src/Elastic.Clients.Elasticsearch/_Shared/Serialization
2 files changed +23
-13
lines changed Original file line number Diff line number Diff line change @@ -24,6 +24,8 @@ internal sealed class DefaultRequestResponseSerializer : SystemTextJsonSerialize
24
24
{
25
25
private readonly IElasticsearchClientSettings _settings ;
26
26
27
+ private readonly object _lock = new ( ) ;
28
+
27
29
public DefaultRequestResponseSerializer ( IElasticsearchClientSettings settings ) :
28
30
base ( new DefaultRequestResponseSerializerOptionsProvider ( settings ) )
29
31
{
@@ -62,14 +64,17 @@ private void LinkSettings(IElasticsearchClientSettings settings)
62
64
var options = GetJsonSerializerOptions ( SerializationFormatting . None ) ;
63
65
var indentedOptions = GetJsonSerializerOptions ( SerializationFormatting . Indented ) ;
64
66
65
- if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
66
- {
67
- ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
68
- }
69
-
70
- if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( indentedOptions , out _ ) )
67
+ lock ( _lock )
71
68
{
72
- ElasticsearchClient . SettingsTable . Add ( indentedOptions , settings ) ;
69
+ if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
70
+ {
71
+ ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
72
+ }
73
+
74
+ if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( indentedOptions , out _ ) )
75
+ {
76
+ ElasticsearchClient . SettingsTable . Add ( indentedOptions , settings ) ;
77
+ }
73
78
}
74
79
}
75
80
}
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ namespace Elastic.Clients.Elasticsearch.Serialization;
21
21
public class DefaultSourceSerializer :
22
22
SystemTextJsonSerializer
23
23
{
24
+ private readonly object _lock = new ( ) ;
25
+
24
26
/// <summary>
25
27
/// Constructs a new <see cref="DefaultSourceSerializer"/> instance that accepts an <see cref="Action{T}"/> that can
26
28
/// be provided to customize the default <see cref="JsonSerializerOptions"/>.
@@ -43,14 +45,17 @@ private void LinkSettings(IElasticsearchClientSettings settings)
43
45
var options = GetJsonSerializerOptions ( SerializationFormatting . None ) ;
44
46
var indentedOptions = GetJsonSerializerOptions ( SerializationFormatting . Indented ) ;
45
47
46
- if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
48
+ lock ( _lock )
47
49
{
48
- ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
49
- }
50
+ if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
51
+ {
52
+ ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
53
+ }
50
54
51
- if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( indentedOptions , out _ ) )
52
- {
53
- ElasticsearchClient . SettingsTable . Add ( indentedOptions , settings ) ;
55
+ if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( indentedOptions , out _ ) )
56
+ {
57
+ ElasticsearchClient . SettingsTable . Add ( indentedOptions , settings ) ;
58
+ }
54
59
}
55
60
}
56
61
}
You can’t perform that action at this time.
0 commit comments