Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error throw when FAKE script exiting #1374

Closed
sillyotter opened this issue Sep 8, 2016 · 0 comments
Closed

Error throw when FAKE script exiting #1374

sillyotter opened this issue Sep 8, 2016 · 0 comments

Comments

@sillyotter
Copy link
Contributor

Description

Infrequently in a script I have, I receive the following exception after everything has run sucessfully and the fake script is just about to exit.

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.NullReferenceException: Object reference not set to an instance of an 
object.

at Fake.ProcessHelper.killAllCreatedProcesses$cont@483(Unit unitVar) in C:\code\fake\src\app\FakeLib\ProcessHelper.fs:line 485
at Fake.TargetHelper.run$cont@511(String targetName, Unit unitVar) in C:\code\fake\src\app\FakeLib\TargetHelper.fs:line 560
at Fake.TargetHelper.run(String targetName) in C:\code\fake\src\app\FakeLib\TargetHelper.fs:line 511
at Fake.AdditionalSyntax.RunTargetOrDefault(String defaultTarget) in C:\code\fake\src\app\FakeLib\AdditionalSyntax.fs:line 29
at <StartupCode$FSI_0005>.$FSI_0005_Build$fsx.main@()                                                                              
--- End of inner exception stack trace ---                                                                                                                                            
at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)                                                                     
at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)                                                                      
at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)                                           
at Fake.FSIHelper.runScriptCached@313.Invoke(Unit unitVar0) in C:\code\fake\src\app\FakeLib\FSIHelper.fs:line 321                                                                     

This does not happen every time.

Repro steps

I have not ever seen this exception until I added a bunch of async code to my script. Specifically, I ExecProcess quite a few TopShelf based services in parallel with code like this below to stop/start/install/uninstall services.

let topshelfServiceAction path args =
    try
        ExecProcess (fun info -> 
                        info.FileName <- path
                        info.WorkingDirectory <- Path.GetDirectoryName(path)
                        info.Arguments <- args
                        info.Verb <- "runas"                        
                        info.UseShellExecute <- true
                    ) 
                    (TimeSpan.FromMinutes 2.0) |> ignore
    with _ -> ()

let stops = seq {
        for i = 0 to instCount do 
            yield async { topshelfServiceAction (ovDir </> "service1.exe") (sprintf "stop -instance:%03i" i) }
            yield async { topshelfServiceAction (difDir </> "service2.exe") (sprintf "stop -instance:%03i" i) }
        yield async { topshelfServiceAction (crDir </> "service3.exe") "stop"}
        yield async { topshelfServiceAction (downDir </> "service4.exe") "stop"}
    }

stops |> Async.Parallel |> Async.RunSynchronously |> ignore

The code works as expected, but as the FAKE script is exiting, I sometimes, not very often, get the error reported above. I'm not 100% sure this caused it, but as the exception is showing the failure in code that is trying to killAllCreatedProcesses, I'm guessing the error is at least somewhat related to all these ExecProcesses.

I haven't had any time to look at the Fake code to see if I could tell what was happening.

Expected behavior

No Exception

Actual behavior

Exception

Related information

  • Windows 10
  • Last FAKE release pulled from nuget on 8Sept2016
  • .Net 4.6
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant