Open
Description
Hello
package main
import (
"context"
"github.com/rabbitmq/amqp091-go"
"sync"
"time"
)
var wg sync.WaitGroup
func amqp(ctx context.Context) {
defer func() {
wg.Done()
}()
c, err := amqp091.Dial("amqp://guest:[email protected]:5672/")
if err != nil {
panic("connection error")
}
defer c.Close()
<-ctx.Done()
}
const n = 16
func main() {
ctx, cancel := context.WithCancel(context.Background())
wg.Add(n)
for i := 0; i < n; i++ {
go amqp(ctx)
}
cancel()
wg.Wait()
time.Sleep(time.Hour)
}
The above code causes 100% CPU usage after a short while
The problem does not always occur, so you may have to run it several times to reproduce the problem
Strace attached after the problem occurred:
strace: Process 3167635 attached
% time seconds usecs/call calls errors syscall
------ ----------- ----------- --------- --------- ----------------
100,00 4,571892 4571892 1 1 futex
0,00 0,000010 5 2 rt_sigprocmask
0,00 0,000002 1 2 getpid
0,00 0,000001 0 2 gettid
0,00 0,000001 0 2 tgkill
0,00 0,000000 0 1 rt_sigaction
------ ----------- ----------- --------- --------- ----------------
100.00 4,571906 10 1 total