Skip to content

Commit

Permalink
fix: Prevent exception on return of job ID to disposed pool
Browse files Browse the repository at this point in the history
  • Loading branch information
mycroes committed Nov 30, 2023
1 parent 39564d3 commit 6fa4fee
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions Sally7/RequestExecutor/ConcurrentRequestExecutor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ private class JobPool : IDisposable
{
private readonly Channel<int> jobIdPool;
private readonly Request[] requests;
private volatile bool disposed;

public JobPool(int maxNumberOfConcurrentRequests)
{
Expand All @@ -209,13 +210,17 @@ public JobPool(int maxNumberOfConcurrentRequests)
}
}

public void Dispose() => jobIdPool.Writer.Complete();
public void Dispose()
{
disposed = true;
jobIdPool.Writer.Complete();
}

public ValueTask<int> RentJobIdAsync(CancellationToken cancellationToken) => jobIdPool.Reader.ReadAsync(cancellationToken);

public void ReturnJobId(int jobId)
{
if (!jobIdPool.Writer.TryWrite(jobId))
if (!jobIdPool.Writer.TryWrite(jobId) && !disposed)
{
Sally7Exception.ThrowFailedToReturnJobIDToPool(jobId);
}
Expand Down

0 comments on commit 6fa4fee

Please sign in to comment.