File tree Expand file tree Collapse file tree 2 files changed +23
-13
lines changed
src/Elastic.Clients.Elasticsearch/_Shared/Serialization Expand file tree Collapse file tree 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
2424{
2525 private readonly IElasticsearchClientSettings _settings ;
2626
27+ private readonly object _lock = new ( ) ;
28+
2729 public DefaultRequestResponseSerializer ( IElasticsearchClientSettings settings ) :
2830 base ( new DefaultRequestResponseSerializerOptionsProvider ( settings ) )
2931 {
@@ -62,14 +64,17 @@ private void LinkSettings(IElasticsearchClientSettings settings)
6264 var options = GetJsonSerializerOptions ( SerializationFormatting . None ) ;
6365 var indentedOptions = GetJsonSerializerOptions ( SerializationFormatting . Indented ) ;
6466
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 )
7168 {
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+ }
7378 }
7479 }
7580}
Original file line number Diff line number Diff line change @@ -21,6 +21,8 @@ namespace Elastic.Clients.Elasticsearch.Serialization;
2121public class DefaultSourceSerializer :
2222 SystemTextJsonSerializer
2323{
24+ private readonly object _lock = new ( ) ;
25+
2426 /// <summary>
2527 /// Constructs a new <see cref="DefaultSourceSerializer"/> instance that accepts an <see cref="Action{T}"/> that can
2628 /// be provided to customize the default <see cref="JsonSerializerOptions"/>.
@@ -43,14 +45,17 @@ private void LinkSettings(IElasticsearchClientSettings settings)
4345 var options = GetJsonSerializerOptions ( SerializationFormatting . None ) ;
4446 var indentedOptions = GetJsonSerializerOptions ( SerializationFormatting . Indented ) ;
4547
46- if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
48+ lock ( _lock )
4749 {
48- ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
49- }
50+ if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
51+ {
52+ ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
53+ }
5054
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+ }
5459 }
5560 }
5661}
You can’t perform that action at this time.
0 commit comments