From c5b2afb42a991aac719da48a5ff2c7fdde36b597 Mon Sep 17 00:00:00 2001 From: cmurialdo Date: Wed, 28 Sep 2022 08:11:01 -0300 Subject: [PATCH] Limit ThreadUtil.WaitForEnd() -that waits for submitted threads to end- to command line context. Exclude it from the web context where it can lead to a deadlock when a web object calls another hosted service (p.e. Rest service) in the same working process, using an intermediate submit call. --- .../GxClasses/Core/GXUtilsCommon.cs | 17 ++++++++++++++--- .../dotnetframework/GxClasses/Model/gxproc.cs | 2 +- 2 files changed, 15 insertions(+), 4 deletions(-) diff --git a/dotnet/src/dotnetframework/GxClasses/Core/GXUtilsCommon.cs b/dotnet/src/dotnetframework/GxClasses/Core/GXUtilsCommon.cs index 28bd2fa76..c63170bb5 100644 --- a/dotnet/src/dotnetframework/GxClasses/Core/GXUtilsCommon.cs +++ b/dotnet/src/dotnetframework/GxClasses/Core/GXUtilsCommon.cs @@ -5821,9 +5821,20 @@ internal static void Submit(WaitCallback callbak, object state) ThreadPool.QueueUserWorkItem( arg => { - callbak(state); - resetEvent.Set(); - events.TryRemove(eventGuid, out ManualResetEvent _); + try + { + callbak(state); + } + catch (Exception ex) + { + GXLogging.Error(log, "Error on submit of " + state.GetType(), ex); + throw; + } + finally + { + resetEvent.Set(); + events.TryRemove(eventGuid, out ManualResetEvent _); + } }); events[eventGuid]= resetEvent; diff --git a/dotnet/src/dotnetframework/GxClasses/Model/gxproc.cs b/dotnet/src/dotnetframework/GxClasses/Model/gxproc.cs index 4f0d4e5ee..6168de075 100644 --- a/dotnet/src/dotnetframework/GxClasses/Model/gxproc.cs +++ b/dotnet/src/dotnetframework/GxClasses/Model/gxproc.cs @@ -91,7 +91,7 @@ protected void exitApplication() } private void exitApplication(bool flushBatchCursor) { - if (IsMain && !(context as GxContext).IsSubmited) + if (!(GxContext.IsHttpContext || GxContext.IsRestService) && IsMain && !(context as GxContext).IsSubmited) ThreadUtil.WaitForEnd(); if (flushBatchCursor)