Skip to content

panic: sync: negative WaitGroup counter #585

@andres-portainer

Description

@andres-portainer

tunnel.waitGroup.Add() causes a panic under certain circumstances with the following message: sync: negative WaitGroup counter, here is an example stack trace:

goroutine 671916 [running]:
sync.(*WaitGroup).Add(0x21b1084?, 0xc008350701?)
    sync/waitgroup.go:64
sync.(*WaitGroup).Done(...)
    sync/waitgroup.go:89
github.com/jpillora/chisel/share/tunnel.(*waitGroup).Done(0xc00413f810?)
    github.com/jpillora/chisel@v1.10.0/share/tunnel/wg.go:20
github.com/jpillora/chisel/share/tunnel.(*waitGroup).DoneAll(...)
    github.com/jpillora/chisel@v1.10.0/share/tunnel/wg.go:26
github.com/jpillora/chisel/share/tunnel.(*Tunnel).BindSSH.func1()
    github.com/jpillora/chisel@v1.10.0/share/tunnel/tunnel.go:79

We are seeing this problem in real world production workloads. The problem is that Add() is not atomic, in the sense that an intermediate state can be observed by DoneAll() (after the atomic.AddInt32() call but before the inner waitgroup Add() call).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions