redis-inside icon indicating copy to clipboard operation
redis-inside copied to clipboard

Undisposed instances keep on running forever

Open mkontula opened this issue 7 years ago • 4 comments

Sometimes when your tests fails, thanks to Visual Studios rock solid (pun-intended) testing runtime, the executable does not get disposed. It would be neat, if we could find a way to kill parentless processes. PowerShell script could run every once in a while in a buildagent VM or redis-inside could use some static shared inventory of started processes. I'd be happy to help with PR if we could first discuss the outlines of the design.

mkontula avatar Feb 25 '18 15:02 mkontula

So I guess even the finalizer does not catch these cases. Would the static inventory work - I mean that is killed as well by Visual Studio right?

How about checking for running process on startup in thread? How would we recognise processes? Could we perhaps tag them with a special argument or something?

Alternatively we could keep a list of processid's somewhere as app-data?

poulfoged avatar Jun 14 '18 13:06 poulfoged

Every new instance get's a process named by guid. Prefixing that by something quite obvious shouldn't beetoo hard. Also a static inventory would help keeping track of instances that are still needed (for example parallel test execution scenarios á la xunit.

Another approach is to dig in to VS testing infra. At the time a debug session crashes (like VS does every once in a while) there must be some event that we could hook up. Funny enough, killing denenv.exe process does not kill the rogue instances.

I'm not aware of the exact details, but it would be kinda great if one could wire the child process to be killed when the host process (vstest.host.exe or something similar) is killed?

mkontula avatar Jun 14 '18 17:06 mkontula

Not the best to depend on Visual Studio test infrastructure or specific host processes I think.

Found some alternatives on this SO thread: https://stackoverflow.com/questions/3342941/kill-child-process-when-parent-process-is-killed

So I see three solutions:

  • Create a small fake debugger and attach to Redis.exe (Don't know how this fares with .NET core and permissions).
  • Using job objects (Same problems as above)
  • Create a child process for each Redis instance (in c#) that is signalled when host process dies and carefully kills the Redis process. (I think this could be quite elegant but also requires some work)

poulfoged avatar Jun 16 '18 08:06 poulfoged

I have a little NuGet process runner that might help for this: https://www.nuget.org/packages/RunProcess/

Use like

using (var proc = new ProcessHost("my.exe", @"C:\temp\")) {
    proc.StartAsChild();
}

i-e-b avatar Oct 10 '18 10:10 i-e-b