[wix-users] WiX Installer hangs intermittently while executing custom action
Rishabh Verma
rishabhv at live.com
Mon Feb 26 01:09:49 PST 2018
Here is the code :)
[CustomAction]
public static ActionResult Execute(Session session)
{
try
{
session.Log("Begin DacpacInstallerAction Execute.");
string upgrading = Parameters.GetParameter<string>(session, Constants.Upgrading, false, string.Empty);
int partialOrComplete = Parameters.GetParameter<int>(session, Constants.PartialOrComplete, false, 0);
bool upgradeScenario = !string.IsNullOrWhiteSpace(upgrading);
bool partialUpgrade = upgradeScenario && partialOrComplete == 1;
if (partialUpgrade)
{
session.Log($"Inplace partial upgrade scenario detected. Full Database/data would not be deployed. Only database migration and incremental deployment would be done. Previous product code(s) - {upgrading}");
///// Need to do DB Migration and then do the dacpac install with createNew set to false.
MigrationDacpacInstaller migrationDacpacInstaller = new MigrationDacpacInstaller(session);
if (!migrationDacpacInstaller.RunMigrationDacpac())
{
throw new ApplicationException("SqlPackage.exe returned a non-zero exit code while migrating database, aborting.");
}
return ActionResult.Success;
}
///// If we are here, it means DB would be installed, so in case registry for first login exists, lets remove it.
TryDeleteRegistry();
DacpacInstaller dacPacInstaller = new DacpacInstaller(session);
//// run SqlPackage.exe to install the DACPAC
if (!dacPacInstaller.RunDacpac())
{
throw new ApplicationException("SqlPackage.exe returned a non-zero exit code, aborting.");
}
return ActionResult.Success;
}
catch (Exception ex)
{
session.Log($"Exception DacpacInstallerAction Execute. Message- {ex.Message}. {Environment.NewLine} Stack Trace- {ex.StackTrace}");
return ActionResult.Failure;
}
finally
{
session.Log("End DacpacInstallerAction Execute.");
}
}
and RunDacpac method looks like this:
public void RunDacpac (bool runAsync = false)
{
//// Set visibility based on parameter
this.Visible = this.parameters.ShowUi;
//// run the process on its own thread
Action action = new Action(() =>
{
//// build the command line parameters to sql package and create the process object to launch it
string commandLineArguments = $"/Action:{this.parameters.Action} \"/SourceFile:{this.parameters.DacpacPath}\" \"/TargetServerName:{this.parameters.TargetServerName}\" \"/TargetDatabaseName:{this.parameters.TargetDatabaseName}\" {this.parameters.OtherParameters}";
string logFilePath = this.parameters.LogFilePath;
Process process = new Process
{
StartInfo = new ProcessStartInfo()
{
FileName = this.parameters.SqlPackagePath,
Arguments = commandLineArguments,
UseShellExecute = false,
CreateNoWindow = true,
RedirectStandardOutput = true,
RedirectStandardError = true
}
};
//// Log the arguments into the log file
this.ProcessOnOutputDataReceived(false, "Parameter to Extension=" + this.parameters?.ToString(), logFilePath);
this.ProcessOnOutputDataReceived(false, "arguments=" + commandLineArguments, logFilePath);
//// hook up to events to read output
process.OutputDataReceived += (s, args) => this.ProcessOnOutputDataReceived(false, args.Data, logFilePath);
process.ErrorDataReceived += (s, args) => this.ProcessOnOutputDataReceived(true, args.Data, logFilePath);
//// Asynchronously read the standard output of the spawned process. This raises OutputDataReceived events for each line of output.
process.Start();
//// read the output
process.BeginOutputReadLine();
process.BeginErrorReadLine();
//// wait for SqlPackage.exe to exit
//// can't call process.WaitForExit() as it will lock up the thread and the UI will lock up
while (!process.HasExited)
{
Thread.SpinWait(250);
}
//// Log the exit code
this.ProcessOnOutputDataReceived(false, "process.ExitCode=" + process.ExitCode, logFilePath);
this.SqlPackageWasSuccessful = process.ExitCode == 0;
//// this.session?.Log($"Returned exit code {process.ExitCode}");
//// Wait for 3 seconds for the user to see the output
Thread.SpinWait(3000);
//// close the form
if (runAsync)
{
this.Invoke(new Action(this.Close));
}
});
if (runAsync)
{
Task.Run(action);
}
else
{
action();
}
}
________________________________
From: Russell Haley <russ.haley at gmail.com>
Sent: Thursday, February 15, 2018 7:22:38 AM
To: Rishabh Verma
Cc: WiX Toolset Users Mailing List
Subject: Re: [wix-users] WiX Installer hangs intermittently while executing custom action
On Wed, Feb 14, 2018 at 11:06 PM, Rishabh Verma <rishabhv at live.com> wrote:
> Hey Russell,
>
>
>
> Thanks for your response. We have tried with the logging enabled and it
> happens only once in while. The log file contains log till the custom action
> is triggered and post that there is no error, just a hang issue. We are
> doing dacPac deployment in the custom action and there are 4 dacpacs that we
> deploy. Invariably it fails in the first or second deployment only and if it
> passes that sate, it completes the deployment without any issue.
>
>
>
> I did Debugger.Launch() in the custom action and didn’t find any issues.
> Infact I added extra logging as well and even that didn’t indicate any issue
> either. If the code review would be helpful, I can share the custom action
> code.
I don't have any knowledge about installing dacpacs, but sharing the
code is always a good way to get others interested. :)
Night,
Russ
>
>
> Thanks,
>
> Rishabh
>
>
>
> Sent from Mail for Windows 10
>
>
>
> From: Russell Haley
> Sent: Thursday, February 15, 2018 10:42 AM
> To: WiX Toolset Users Mailing List
> Cc: Rishabh Verma
> Subject: Re: [wix-users] WiX Installer hangs intermittently while executing
> custom action
>
>
>
> Sorry, hit the wrong button. Have you tried it with logging turned on?
>
> msiexec /i "my-installer.msi" /L*V "my-installer.log"
>
> This might give you some reference, or might not be helpful at all.
> Perhaps some indication in your email about what the custom action is
> doing would be helpful to suggest debugging? A couple thoughts come to
> mind: A resource is in use and can't be removed, a UI element has been
> created to ask for information from the user and no UI is available.
>
> Has the CustomAction been independently debugged?
>
> Russ
>
> On Wed, Feb 14, 2018 at 9:06 PM, Russell Haley <russ.haley at gmail.com> wrote:
>> Hi,
>>
>> Have you tried running the installer with logging on?
>>
>>
>> On Wed, Feb 14, 2018 at 7:21 PM, Rishabh Verma via wix-users
>> <wix-users at lists.wixtoolset.org> wrote:
>>> Folks,
>>>
>>>
>>> It has been observed that running a WiX installer with a custom action is
>>> getting stuck once in a while executing custom action. Based on the
>>> analysis, the machines in which this issue occurred had not been restarted
>>> for 8-9 days. We analyzed the wait chain and found that msiexec was waiting
>>> for rundll32.exe. On killing rundll32.exe, the setup rolled back. Any
>>> pointers to get around this issue would be great as we are about to release
>>> this to customer
>>> Thanks,
>>> Rishabh
>>>
>>>
>>>
>>> ____________________________________________________________________
>>> WiX Toolset Users Mailing List provided by FireGiant
>>> http://www.firegiant.com/
>
>
More information about the wix-users
mailing list