Skip to content

Commit 9062721

Browse files
committed
use max size semaphore
fix double release stack-info: PR: #4220, branch: GarrettBeatty/gcbeatty/taskoptimization/3
1 parent ef08cbf commit 9062721

File tree

3 files changed

+8
-5
lines changed

3 files changed

+8
-5
lines changed

sdk/src/Services/S3/Custom/Transfer/Internal/BufferedPartDataHandler.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,6 @@ private void ProcessStreamingPart(
153153
// If ReleaseBufferSpace() throws, we no longer own the data source, so we won't dispose it
154154
streamingDataSource = null;
155155

156-
// Release capacity immediately since we're not holding anything in memory
157-
_partBufferManager.ReleaseBufferSpace();
158-
159156
_logger.DebugFormat("BufferedPartDataHandler: [Part {0}] StreamingDataSource added and capacity released",
160157
partNumber);
161158
}

sdk/src/Services/S3/Custom/Transfer/Internal/MultipartDownloadManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,10 @@ public MultipartDownloadManager(IAmazonS3 s3Client, BaseDownloadRequest request,
159159
}
160160
else
161161
{
162-
_httpConcurrencySlots = new SemaphoreSlim(_config.ConcurrentServiceRequests);
162+
_httpConcurrencySlots = new SemaphoreSlim(
163+
_config.ConcurrentServiceRequests, // initialCount
164+
_config.ConcurrentServiceRequests // maxCount - prevents exceeding configured limit
165+
);
163166
_ownsHttpThrottler = true; // We own it, so we dispose it
164167
}
165168
}

sdk/src/Services/S3/Custom/Transfer/Internal/PartBufferManager.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,10 @@ public PartBufferManager(BufferedDownloadConfiguration config)
199199
throw new ArgumentNullException(nameof(config));
200200

201201
_partDataSources = new ConcurrentDictionary<int, IPartDataSource>();
202-
_bufferSpaceAvailable = new SemaphoreSlim(config.MaxInMemoryParts);
202+
_bufferSpaceAvailable = new SemaphoreSlim(
203+
config.MaxInMemoryParts, // initialCount
204+
config.MaxInMemoryParts // maxCount - prevents exceeding configured limit
205+
);
203206
_partAvailable = new AutoResetEvent(false);
204207

205208
Logger.DebugFormat("PartBufferManager initialized with MaxInMemoryParts={0}", config.MaxInMemoryParts);

0 commit comments

Comments
 (0)