8000 Fix releasing poolInitSemaphore · cnblogs/EnyimMemcachedCore@80e479f · GitHub
[go: up one dir, main page]

Skip to content

Commit 80e479f

Browse files
committed
Fix releasing poolInitSemaphore
1 parent 53d590b commit 80e479f

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

Enyim.Caching/Memcached/MemcachedNode.cs

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,12 +130,19 @@ public IPooledSocketResult Acquire()
130130
if (!this.isInitialized)
131131
{
132132
poolInitSemaphore.Wait();
133-
if (!this.isInitialized)
133+
try
134134
{
135-
var startTime = DateTime.Now;
136-
this.internalPoolImpl.InitPool();
137-
this.isInitialized = true;
138-
_logger.LogInformation("MemcachedInitPool-cost: {0}ms", (DateTime.Now - startTime).TotalMilliseconds);
135+
if (!this.isInitialized)
136+
{
137+
var startTime = DateTime.Now;
138+
this.internalPoolImpl.InitPool();
139+
this.isInitialized = true;
140+
_logger.LogInformation("MemcachedInitPool-cost: {0}ms", (DateTime.Now - startTime).TotalMilliseconds);
141+
}
142+
}
143+
finally
144+
{
145+
poolInitSemaphore.Release();
139146
}
140147
}
141148

@@ -151,10 +158,6 @@ public IPooledSocketResult Acquire()
151158
result.Fail(message, e);
152159
return result;
153160
}
154-
finally
155-
{
156-
poolInitSemaphore.Release();
157-
}
158161
}
159162

160163
/// <summary>
@@ -166,12 +169,18 @@ public async Task<IPooledSocketResult> AcquireAsync()
166169
if (!this.isInitialized)
167170
{
168171
await poolInitSemaphore.WaitAsync();
169-
if (!this.isInitialized)
172+
try
173+
{
174+
if (!this.isInitialized)
175+
{
176+
var startTime = DateTime.Now;
177+
await this.internalPoolImpl.InitPoolAsync();
178+
this.isInitialized = true;
179+
_logger.LogInformation("MemcachedInitPool-cost: {0}ms", (DateTime.Now - startTime).TotalMilliseconds);
180+
}
181+
}
182+
finally
170183
{
171-
var startTime = DateTime.Now;
172-
await this.internalPoolImpl.InitPoolAsync();
173-
this.isInitialized = true;
174-
_logger.LogInformation("MemcachedInitPool-cost: {0}ms", (DateTime.Now - startTime).TotalMilliseconds);
175184
poolInitSemaphore.Release();
176185
}
177186
}

0 commit comments

Comments
 (0)
0