8000 GitHub · Where software is built
[go: up one dir, main page]

8000
Skip to content
v6-transport: PackSession.Handshake() can leak cmd and/or a goroutine, and has a data race #1526
Open
@mhagger

Description

@mhagger

In branch v6-transport, PackSession.Handshake()[starts up a goroutine](https://github.com/go-git/go-git/blob/675edb808690b47e0a9cb99c44a0f2b8245209a6/plumbing/transport/pack.go#L91) to copy data fromstderrto&c.stderrBufand then [starts something usingcmd.Start()](https://github.com/go-git/go-git/blob/675edb808690b47e0a9cb99c44a0f2b8245209a6/plumbing/transport/pack.go#L97). (What cmd.Start()` starts seems to depend on the details, but I presume that at least sometimes it needs to be stopped.)

But if PackSession.Handshake() exits with an error after one or both of these steps is complete, the goroutine, or both the goroutine and the cmd, are never stopped and seem to be leaked.

Moreover, the same method uses a defer to copy the stderr buffer into err. But nothing prevents this defer from running before the copy goroutine has completed writing into the same stderr buffer. This therefore constitutes a data race. (I've observed this race using the race detector.)

/cc @aymanbagabas, who I think worked on this part of the code.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      0