44
55using System . Collections . Generic ;
66using System . IO ;
7+ using System . Runtime . Serialization ;
78using System . Text . Json ;
89using System . Text . Json . Serialization ;
910using System . Threading ;
@@ -24,6 +25,8 @@ internal sealed class DefaultRequestResponseSerializer : SystemTextJsonSerialize
2425{
2526 private readonly IElasticsearchClientSettings _settings ;
2627
28+ private readonly object _lock = new ( ) ;
29+
2730 public DefaultRequestResponseSerializer ( IElasticsearchClientSettings settings ) :
2831 base ( new DefaultRequestResponseSerializerOptionsProvider ( settings ) )
2932 {
@@ -62,14 +65,17 @@ private void LinkSettings(IElasticsearchClientSettings settings)
6265 var options = GetJsonSerializerOptions ( SerializationFormatting . None ) ;
6366 var indentedOptions = GetJsonSerializerOptions ( SerializationFormatting . Indented ) ;
6467
65- if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
66- {
67- ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
68- }
69-
70- if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( indentedOptions , out _ ) )
68+ lock ( _lock )
7169 {
72- ElasticsearchClient . SettingsTable . Add ( indentedOptions , settings ) ;
70+ if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( options , out _ ) )
71+ {
72+ ElasticsearchClient . SettingsTable . Add ( options , settings ) ;
73+ }
74+
75+ if ( ! ElasticsearchClient . SettingsTable . TryGetValue ( indentedOptions , out _ ) )
76+ {
77+ ElasticsearchClient . SettingsTable . Add ( indentedOptions , settings ) ;
78+ }
7379 }
7480 }
7581}
0 commit comments