Skip to content

Commit e2cf427

Browse files
committed
Don't call Abort() if operation is alredy in aborting state
1 parent c6f1148 commit e2cf427

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

Mono.Debugging/Mono.Debugging.Evaluation/AsyncOperationBase.cs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ public interface IAsyncOperationBase
3232
{
3333
Task RawTask { get; }
3434
string Description { get; }
35+
bool AbortCalled { get; }
3536
void Abort ();
3637
}
3738

@@ -59,6 +60,8 @@ public Task RawTask
5960
/// </summary>
6061
protected CancellationToken Token { get { return tokenSource.Token; } }
6162

63+
public bool AbortCalled { get { return Token.IsCancellationRequested; } }
64+
6265
public void Abort ()
6366
{
6467
try {

Mono.Debugging/Mono.Debugging.Evaluation/AsyncOperationManager.cs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -76,9 +76,12 @@ public OperationResult<TValue> Invoke<TValue> (AsyncOperationBase<TValue> mc, in
7676
return task.Result;
7777
}
7878
DebuggerLoggingService.LogMessage (string.Format ("Invoke {0} timed out after {1} ms. Cancelling.", description, timeout));
79-
mc.Abort ();
79+
var abortCalled = mc.AbortCalled;
80+
// if abort was already called (in AbortAll/Dispose) don't call it again, just wait
81+
if (!abortCalled)
82+
mc.Abort ();
8083
try {
81-
WaitAfterCancel (mc);
84+
WaitAfterCancel (mc, abortCalled);
8285
}
8386
catch (Exception e) {
8487
if (IsOperationCancelledException (e)) {
@@ -119,7 +122,7 @@ void ChangeBusyState (bool busy, string description)
119122
}
120123
}
121124

122-
void WaitAfterCancel (IAsyncOperationBase op)
125+
void WaitAfterCancel (IAsyncOperationBase op, bool onlyWait)
123126
{
124127
var desc = op.Description;
125128
DebuggerLoggingService.LogMessage (string.Format ("Waiting for cancel of invoke {0}", desc));
@@ -131,7 +134,9 @@ void WaitAfterCancel (IAsyncOperationBase op)
131134
if (disposed)
132135
break;
133136
}
134-
op.Abort ();
137+
if (!onlyWait) {
138+
op.Abort ();
139+
}
135140
if (op.RawTask.Wait (ShortCancelTimeout))
136141
break;
137142
}
@@ -160,9 +165,13 @@ void CancelOperations (List<IAsyncOperationBase> operations, bool wait)
160165
foreach (var operation in operations) {
161166
var taskDescription = operation.Description;
162167
try {
163-
operation.Abort ();
168+
var abortCalled = operation.AbortCalled;
169+
// if abort was already called (in AbortAll/Dispose) don't call it again, just wait
170+
if (!abortCalled) {
171+
operation.Abort ();
172+
}
164173
if (wait) {
165-
WaitAfterCancel (operation);
174+
WaitAfterCancel (operation, abortCalled);
166175
}
167176
}
168177
catch (Exception e) {

0 commit comments

Comments
 (0)