you should do this after waiting for the process to exit  as it may still be writing to the log at this point  i do not think you need s fatal on l since it is already the last thing in a deferred function in your test function  i e  the test is done at this point  so i would just do this defer func cr close ctx if err wpr kill err nil s error wpr wait ignore error since we killed the process if err wprgzippedlog close err nil s error 