Skip to content

Commit 6fe7ec8

Browse files
committed
Work on tests
1 parent bc2bcde commit 6fe7ec8

1 file changed

Lines changed: 9 additions & 11 deletions

File tree

  • Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/ResponseStreaming

Libraries/src/Amazon.Lambda.RuntimeSupport/Bootstrap/ResponseStreaming/ResponseStream.cs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ internal class ResponseStream
3636

3737
// The live HTTP output stream, set by RawStreamingHttpClient when sending the streaming response.
3838
private Stream _httpOutputStream;
39-
private bool _disposedValue;
39+
private int _disposedFlag;
4040

4141
// The wait time is a sanity timeout to avoid waiting indefinitely if SetHttpOutputStreamAsync is not called or takes too long to call.
4242
// Reality is that SetHttpOutputStreamAsync should be called very quickly after CreateStream, so this timeout is generous to avoid false positives but still protects against hanging indefinitely.
@@ -233,18 +233,16 @@ private void ThrowIfCompletedOrError()
233233
/// <param name="disposing"></param>
234234
protected virtual void Dispose(bool disposing)
235235
{
236-
if (!_disposedValue)
237-
{
238-
if (disposing)
239-
{
240-
try { _httpStreamReady.Release(); } catch (SemaphoreFullException) { /* Ignore if already released */ }
241-
_httpStreamReady.Dispose();
236+
if (Interlocked.Exchange(ref _disposedFlag, 1) != 0)
237+
return;
242238

243-
try { _completionSignal.Release(); } catch (SemaphoreFullException) { /* Ignore if already released */ }
244-
_completionSignal.Dispose();
245-
}
239+
if (disposing)
240+
{
241+
try { _httpStreamReady.Release(); } catch (SemaphoreFullException) { /* Ignore if already released */ }
242+
_httpStreamReady.Dispose();
246243

247-
_disposedValue = true;
244+
try { _completionSignal.Release(); } catch (SemaphoreFullException) { /* Ignore if already released */ }
245+
_completionSignal.Dispose();
248246
}
249247
}
250248

0 commit comments

Comments
 (0)