mirror of
https://github.com/ckaczor/sqltoolsservice.git
synced 2026-02-16 10:58:30 -05:00
Switch back to event from locks to fix blocking issues. (#111)
This commit is contained in:
@@ -15,7 +15,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
/// Main class for the Binding Queue
|
||||
/// </summary>
|
||||
public class BindingQueue<T> where T : IBindingContext, new()
|
||||
{
|
||||
{
|
||||
private CancellationTokenSource processQueueCancelToken = new CancellationTokenSource();
|
||||
|
||||
private ManualResetEvent itemQueuedEvent = new ManualResetEvent(initialState: false);
|
||||
@@ -197,14 +197,18 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
// prefer the queue item binding item, otherwise use the context default timeout
|
||||
int bindTimeout = queueItem.BindingTimeout ?? bindingContext.BindingTimeout;
|
||||
|
||||
// handle the case a previous binding operation is still running
|
||||
if (!Monitor.TryEnter(bindingContext.BindingLock, bindTimeout))
|
||||
// handle the case a previous binding operation is still running
|
||||
if (!bindingContext.BindingLock.WaitOne(0))
|
||||
{
|
||||
queueItem.Result = queueItem.TimeoutOperation(bindingContext);
|
||||
queueItem.ItemProcessed.Set();
|
||||
queueItem.Result = queueItem.TimeoutOperation != null
|
||||
? queueItem.TimeoutOperation(bindingContext)
|
||||
: null;
|
||||
|
||||
continue;
|
||||
}
|
||||
|
||||
bindingContext.BindingLock.Reset();
|
||||
|
||||
lockTaken = true;
|
||||
|
||||
// execute the binding operation
|
||||
@@ -231,9 +235,10 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
{
|
||||
queueItem.Result = queueItem.TimeoutOperation(bindingContext);
|
||||
}
|
||||
|
||||
lockTaken = false;
|
||||
|
||||
// we'll need to wait for the task to finsh canceling otherwise future binding will fail
|
||||
bindTask.Wait();
|
||||
bindTask.ContinueWith((a) => bindingContext.BindingLock.Set());
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -246,7 +251,7 @@ namespace Microsoft.SqlTools.ServiceLayer.LanguageServices
|
||||
{
|
||||
if (lockTaken)
|
||||
{
|
||||
Monitor.Exit(bindingContext.BindingLock);
|
||||
bindingContext.BindingLock.Set();
|
||||
}
|
||||
|
||||
queueItem.ItemProcessed.Set();
|
||||
|
||||
Reference in New Issue
Block a user