Skip to content
  • Ben Gamari's avatar
    Refactor waiting on job objects · 3138b775
    Ben Gamari authored
    Previously in order to wait on a job object we would create an IO
    Completion Port, configure the job object to emit notifications to it
    with SetInformationJobObject, and wait for JOB_OBJECT_MSG_EXIT_PROCESS
    notifications until all processes have died.
    
    This followed one piece of guidance from Microsoft [1] but according to
    Microsoft's own documentation, this cannot work reliably as delivery of
    job notifications is not guaranteed [2]. I have seen cases where the
    processes hang waiting on job objects so I can only guess that message
    loss is indeed possible.
    
    Instead we now take a simpler approach: look at the processes in the
    job, if there are none then we are done. If there are still processes,
    choose one and wait for it to finish. Iterate until the job is empty.
    
    Credit for this approach goes to Davean Scies.
    
    [1] https://devblogs.microsoft.com/oldnewthing/20130405-00/?p=4743
    [2] https://docs.microsoft.com/en-us/windows/win32/api/winnt/ns-winnt-jobobject_associate_completion_port
    3138b775