BlackbirdSQL / Firebird-DDEX-SqlEditor

Firebird DDEX 2.0 with SqlEditor NETProvider
4 stars 1 forks source link

SetSite failed for package [BlackbirdSqlDdexExtension]Source: 'mscorlib' Description: A task may only be disposed if it is in a completion state (RanToCompletion, Faulted or Canceled). #23

Closed MagicAndre1981 closed 4 months ago

MagicAndre1981 commented 4 months ago

In 17.10 Preview 1 I just got a message at VS startup that your extension failed to load and activitylog.xml shows this error:

SetSite failed for package [BlackbirdSqlDdexExtension]Source: 'mscorlib' Description: A task may only be disposed if it is in a completion state (RanToCompletion, Faulted or Canceled).
System.InvalidOperationException: A task may only be disposed if it is in a completion state (RanToCompletion, Faulted or Canceled).
   at System.Threading.Tasks.Task.Dispose(Boolean disposing)
   at BlackbirdSql.Core.Model.AbstruseRunningConnectionTable.ClearSyncPayloadLauncher() in C:\Server\Dev\Projects2022\Blackbird\BlackbirdSql.Core\Model\AbstruseRunningConnectionTable.cs:line 602
   at BlackbirdSql.Core.Model.AbstruseRunningConnectionTable.SyncExit() in C:\Server\Dev\Projects2022\Blackbird\BlackbirdSql.Core\Model\AbstruseRunningConnectionTable.cs:line 2248
   at BlackbirdSql.Core.Model.AbstruseRunningConnectionTable.LoadConfiguredConnections() in C:\Server\Dev\Projects2022\Blackbird\BlackbirdSql.Core\Model\AbstruseRunningConnectionTable.cs:line 809
   at BlackbirdSql.Core.Model.RctManager.ResolveDeadlocks(Boolean asynchronous) in C:\Server\Dev\Projects2022\Blackbird\BlackbirdSql.Core\Model\RctManager.cs:line 672
   at BlackbirdSql.Controller.ControllerAsyncPackage.<FinalizeAsync>d__8.MoveNext() in C:\Server\Dev\Projects2022\Blackbird\BlackbirdSql.Controller\ControllerAsyncPackage.cs:line 163
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at BlackbirdSql.VisualStudio.Ddex.BlackbirdSqlDdexExtension.<FinalizeAsync>d__13.MoveNext() in C:\Server\Dev\Projects2022\Blackbird\BlackbirdSql.VisualStudio.Ddex\BlackbirdSqlDdexExtension.cs:line 319
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at BlackbirdSql.VisualStudio.Ddex.BlackbirdSqlDdexExtension.<InitializeAsync>d__12.MoveNext() in C:\Server\Dev\Projects2022\Blackbird\BlackbirdSql.VisualStudio.Ddex\BlackbirdSqlDdexExtension.cs:line 288
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Microsoft.VisualStudio.Shell.AsyncPackage.<>c__DisplayClass21_0.<<Microsoft-VisualStudio-Shell-Interop-IAsyncLoadablePackageInitialize-Initialize>b__1>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Microsoft.VisualStudio.Services.VsTask.RethrowException(AggregateException e)
   at Microsoft.VisualStudio.Services.VsTask.InternalGetResult(Boolean ignoreUIThreadCheck)
ErikEJ commented 4 months ago

@MagicAndre1981 Are you running the latest version?

BlackbirdSQL commented 4 months ago

@MagicAndre1981 Are you running the latest version?

Can you confirm the version you are running?

MagicAndre1981 commented 4 months ago

yes, I use 11.0.0.1 but can't repro it now. I think I had the kill VS2022 as it got frozen and on next satrtup I saw this message. I'll see if this happens again

BlackbirdSQL commented 4 months ago

yes, I use 11.0.0.1 but can't repro it now. I think I had the kill VS2022 as it got frozen and on next strtup I saw this message. I'll see if this happens again

Okay, but nonethless, can you recall the conditions under which the original freeze occurred? eg. Was it on IDE startup or after the IDE had fully loaded etc. ? I am finding that when I install a VS async extension, then on next startup the IDE will sometimes freeze up before it has started loading any async extensions, which occur very late in the startup cycle, after the SE has loaded and any solution. Was this the scenario in your case?

MagicAndre1981 commented 4 months ago

VS got frozen at solution close (solution with around 30 projects) and here I had to kill VS and on I think on next startup I got the message.

I switched to LTSC to stay on 17.8, the 17.9/17.10 are slow for me. I'll continue do nuget updates and tests now on 17.8 LTSC and see if I have error there, too.

BlackbirdSQL commented 4 months ago

BlackbirdSql will record any shutdown/close issues (and any other extension exceptions) to a log file in the specified temp folder if you check Enable diagnostics logging under User Options > BlackbirdSQL Server Tools > Ddex > Debug. There is no overhead to enabling this option. If the freeze did have anything to do with the Extension then there's a good chance it will have been logged to the log file if the logging option is enabled. If you do enable logging just be aware that the log file is never reset, so it would have to be deleted manually.

BlackbirdSQL commented 4 months ago

... one more thing ... In the event the freeze is due to a deadlock bug in BlackbirdSql, the timeout on breaking the deadlock can be anything up to 15 seconds in the RunningConnectionTable and up to 30 seconds in the trigger LinkageParser, so if the freeze was related to one of these, an exception would only raised and logged after the timeout period has elapsed.

MagicAndre1981 commented 4 months ago

the VS preview worked fine today (no need to kill the frozen VS) and the delay comes from a different extension. I actived the logging but see no log file.

So add a TaskStatus check for TaskStatus RanToCompletion, Faulted or Canceled before calling Dispose in your code to avoid this.

BlackbirdSQL commented 4 months ago

the VS preview worked fine today (no need to kill the frozen VS) and the delay comes from a different extension. I actived the logging but see no log file.

Yes, the log file will only appear if there is something to log.

So add a TaskStatus check for TaskStatus RanToCompletion, Faulted or Canceled before calling Dispose in your code to avoid this.

Yes thanks there is now a catch for a graceful exit, but this state should never occur, otherwise there's a bug. Has it happened again?

BlackbirdSQL commented 4 months ago

Yes thanks there is now a catch for a graceful exit, but this state should never occur, otherwise there's a bug. Has it happened again?

Okay I believe I've found the problem. If the Sync token is cancelled and Dispose() is then called during the 50ms sleep of the Sync task loop, it won't have exited. In all this time since the Rct was implemented, this has never happened to me, is why it was never detected. There is no guarantee that waiting any period of time after the cancel request that the Sync task waiter will have exited because it runs on a thread in the thread pool, so your suggestion will work.

MagicAndre1981 commented 4 months ago

Okay I believe I've found the problem. If the Sync token is cancelled and Dispose() is then called during the 50ms sleep of the Sync task loop, it won't have exited. In all this time since the Rct was implemented, this has never happened to me,

ok, nice to hear that you found the cause and for me it only happend once so no wonder why you haven't seen this before.

BlackbirdSQL commented 4 months ago

This issue has been resolved in Release 11.1.0.0.