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

add a delay to prevent object disposed exceptions from process on macosx #1426

Merged
merged 1 commit into from
Nov 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions src/app/FakeLib/ProcessHelper.fs
Original file line number Diff line number Diff line change
Expand Up @@ -434,22 +434,29 @@ let asyncShellExec (args : ExecParams) =
let info =
ProcessStartInfo
(args.Program, UseShellExecute = false,
RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = true,
WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = args.WorkingDirectory,
Arguments = commandLine)
use proc = new Process(StartInfo = info)
proc.ErrorDataReceived.Add(fun e ->
if e.Data <> null then traceError e.Data)
proc.OutputDataReceived.Add(fun e ->
if e.Data <> null then log e.Data)
start proc
proc.BeginOutputReadLine()
proc.BeginErrorReadLine()
proc.StandardInput.Close()
// attaches handler to Exited event, enables raising events, then awaits event
// the event gets triggered even if process has already finished
let! _ = Async.GuardedAwaitObservable proc.Exited (fun _ -> proc.EnableRaisingEvents <- true)
return proc.ExitCode
RedirectStandardError = true, RedirectStandardOutput = true, RedirectStandardInput = true,
WindowStyle = ProcessWindowStyle.Hidden, WorkingDirectory = args.WorkingDirectory,
Arguments = commandLine)
let proc = new Process(StartInfo = info)

try
proc.ErrorDataReceived.Add(fun e ->
if e.Data <> null then traceError e.Data)
proc.OutputDataReceived.Add(fun e ->
if e.Data <> null then log e.Data)
start proc
proc.BeginOutputReadLine()
proc.BeginErrorReadLine()
proc.StandardInput.Close()
// attaches handler to Exited event, enables raising events, then awaits event
// the event gets triggered even if process has already finished
let! _ = Async.GuardedAwaitObservable proc.Exited (fun _ -> proc.EnableRaisingEvents <- true)
return proc.ExitCode
finally
// add a delay because we were seeing ObjectDisposedException when running shell commands on
// osx. Github issue #1424.
Async.Sleep (10) |> Async.RunSynchronously
proc.Dispose()
}

/// Kills the given process
Expand Down