4
4
5
5
using System . Collections . Generic ;
6
6
using System . IO ;
7
+ using System . Runtime . Serialization ;
7
8
using System . Text . Json ;
8
9
using System . Text . Json . Serialization ;
9
10
using System . Threading ;
@@ -24,6 +25,8 @@ internal sealed class DefaultRequestResponseSerializer : SystemTextJsonSerialize
24
25
{
25
26
private readonly IElasticsearchClientSettings _settings ;
26
27
28
+ private readonly object _lock = new ( ) ;
29
+
27
30
public DefaultRequestResponseSerializer ( IElasticsearchClientSettings settings ) :
28
31
base ( new DefaultRequestResponseSerializerOptionsProvider ( settings ) )
29
32
{
@@ -62,14 +65,17 @@ private void LinkSettings(IElasticsearchClientSettings settings)
62
65
var options = GetJsonSerializerOptions ( SerializationFormatting . None ) ;
63
66
var indentedOptions = GetJsonSerializerOptions ( SerializationFormatting . Indented ) ;
64
67
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 )
71
69
{
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
+ }
73
79
}
74
80
}
75
81
}
0 commit comments