Skip to content

prevents a goroutine from being leaked if binary cmd fails to finish#993

Merged
dcantah merged 1 commit intomicrosoft:masterfrom
hex0punk:goroutine-leak-fix
Apr 8, 2021
Merged

prevents a goroutine from being leaked if binary cmd fails to finish#993
dcantah merged 1 commit intomicrosoft:masterfrom
hex0punk:goroutine-leak-fix

Conversation

@hex0punk
Copy link
Contributor

@hex0punk hex0punk commented Apr 8, 2021

Prevents an egde case where a goroutine would be leaked when the following case executes

		case <-time.After(binaryCmdWaitTimeout):
			log.G(ctx).Errorf("timeout while waiting for binaryIO process to finish. Killing")
			err := b.cmd.Process.Kill()
			if err != nil {
				log.G(ctx).WithError(err).Errorf("error while killing binaryIO process")
			}
		}

If the above occurs before or at the same time as the case below (and the scheduler chooses to the above case), the goroutine above the select block would be leaked as it is blocked by the send to the done channel.

		go func() {
			done <- b.cmd.Wait()
		}()

		select {
		case err := <-done:
			if err != nil {
				log.G(ctx).WithError(err).Errorf("error while waiting for binary cmd to finish")
			}

@hex0punk hex0punk requested a review from a team as a code owner April 8, 2021 08:10
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

Successfully merging this pull request may close these issues.

2 participants