rhythmagency / formulate

An advanced form builder for Umbraco.
MIT License
92 stars 50 forks source link

Avoid Errors on Install #19

Open Nicholas-Westby opened 8 years ago

Nicholas-Westby commented 8 years ago

Sometimes, errors occur when installing the Formulate package. My guess is this is because Formulate will run some code on application start that can make a number of modifications (e.g., to config files) that will initiate an application pool recycle. They may be tripping over each other, or they may be interfering with the package installer in Umbraco.

One idea would be to use QueueBackgroundWorkItem (QBWI) to delay application pool recycles until after all config changes have been made: https://blogs.msdn.microsoft.com/webdev/2014/06/04/queuebackgroundworkitem-to-reliably-schedule-and-run-background-processes-in-asp-net/

Another idea would be to delay the config changes a few seconds so the package installer has a chance to finish. The downside of that is that some people may be quick to close Umbraco after the package installation and wouldn't run the other config changes until the next time they run the site (which may lead to some confusion, as changes would be made for what would seem to them to be no apparent reason).

Will start with the QBWI idea, then try the delay if necessary.

FYI, a temporary workaround is to install Formulate twice. The first install does all the modifications (e.g., config transforms). The second install ensures everything is there.

Nicholas-Westby commented 8 years ago

Here's another crazy idea:

install-screen

That's the screen I display when Formulate has finished installing. I could have it initiate an AJAX request to the server to let it know that it's safe to start making configuration changes. If that request isn't sent within 60 seconds or so (possible if somebody attempts to manually install Formulate on the file system, or if they close the browser), I can start making the configuration changes anyway.

Nicholas-Westby commented 8 years ago

Useful reference: https://blog.mariusschulz.com/2014/05/07/scheduling-background-jobs-from-an-asp-net-application-in-net-4-5-2

Nicholas-Westby commented 8 years ago

Opening this back up, as I just saw a 500 error when upgrading from Formulate 0.1.0.7 to 0.2.2.0.

Nicholas-Westby commented 8 years ago

My guess is these entries in my Umbraco error log are related:

 2016-04-15 13:28:03,017 [P6520/D8/T14] ERROR Umbraco.Core.UmbracoApplicationBase - An unhandled exception occurred
System.InvalidOperationException: The task runner has completed.
   at Umbraco.Web.Scheduling.BackgroundTaskRunner`1.Add(T task)
   at Umbraco.Web.Strategies.ServerRegistrationEventHandler.RegisterServer(UmbracoRequestEventArgs e)
   at Umbraco.Web.Strategies.ServerRegistrationEventHandler.UmbracoModuleRouteAttempt(Object sender, RoutableAttemptEventArgs e)
   at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
   at Umbraco.Web.UmbracoModule.OnRouteAttempt(RoutableAttemptEventArgs args)
   at Umbraco.Web.UmbracoModule.ProcessRequest(HttpContextBase httpContext)
   at Umbraco.Web.UmbracoModule.<Init>b__8(Object sender, EventArgs e)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
 2016-04-15 13:28:03,020 [P6520/D8/T14] ERROR AllCare.App.Application.AllCareApplication - An error was captured by OnApplicationError handler.
System.InvalidOperationException: The task runner has completed.
   at Umbraco.Web.Scheduling.BackgroundTaskRunner`1.Add(T task)
   at Umbraco.Web.Strategies.ServerRegistrationEventHandler.RegisterServer(UmbracoRequestEventArgs e)
   at Umbraco.Web.Strategies.ServerRegistrationEventHandler.UmbracoModuleRouteAttempt(Object sender, RoutableAttemptEventArgs e)
   at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
   at Umbraco.Web.UmbracoModule.OnRouteAttempt(RoutableAttemptEventArgs args)
   at Umbraco.Web.UmbracoModule.ProcessRequest(HttpContextBase httpContext)
   at Umbraco.Web.UmbracoModule.<Init>b__8(Object sender, EventArgs e)
   at System.Web.HttpApplication.SyncEventExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute()
   at System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously)
Nicholas-Westby commented 8 years ago

Might be a core bug that is fixed in Umbraco 7.4.2. More discussion here: https://our.umbraco.org/forum/developers/api-questions/74885-changes-in-737-package-installer-process