The Go Programming Language
http://golang.org/
Go Playground
Go Projects
Revel Web Framework
luxcgo

这里有 goroutine 的泄露问题吗?

  •  
  •   luxcgo · Feb 23, 2022 · 2167 views
    This topic created in 1542 days ago, the information mentioned may be changed or developed.

    开始和结束的时候的 goroutine 数量不一致

    Supplement 1  ·  Feb 23, 2022
    1
    ^C2022/02/23 13:44:13 收到结束信号(interrupt),准备结束进程
    goroutine profile: total 2
    1 @ 0x40a554 0x45d018 0x498cf9 0x4606e1
    #       0x45d017        os/signal.signal_recv+0x97      /usr/lib/go-1.17/src/runtime/sigqueue.go:169
    #       0x498cf8        os/signal.loop+0x18             /usr/lib/go-1.17/src/os/signal/signal_unix.go:24
    
    1 @ 0x45bca5 0x4a8c55 0x4a8a6d 0x4a5beb 0x4b23f4 0x434c47 0x4606e1
    #       0x45bca4        runtime/pprof.runtime_goroutineProfileWithLabels+0x24   /usr/lib/go-1.17/src/runtime/mprof.go:746
    #       0x4a8c54        runtime/pprof.writeRuntimeProfile+0xb4                  /usr/lib/go-1.17/src/runtime/pprof/pprof.go:724
    #       0x4a8a6c        runtime/pprof.writeGoroutine+0x4c                       /usr/lib/go-1.17/src/runtime/pprof/pprof.go:684
    #       0x4a5bea        runtime/pprof.(*Profile).WriteTo+0x14a                  /usr/lib/go-1.17/src/runtime/pprof/pprof.go:331
    #       0x4b23f3        main.main+0xb3                                          /home/lucas/github/go-snippet/leak/main.go:37
    #       0x434c46        runtime.main+0x226                                      /usr/lib/go-1.17/src/runtime/proc.go:255
    

    经过 pprof 的分析后,多的一个 goroutine 是 signal 创建的

    这个 goroutine 如何退出呢

    在开发的过程中是不是要掌握所有 goroutine 的生命周期,在程序结束时先清理 goroutine,等他们都退出了整个程序再退出

    5 replies    2022-02-23 13:53:33 +08:00
    CEBBCAT
        1
    CEBBCAT  
       Feb 23, 2022 via iPhone
    那一个 goroutine ,会不会是 signal 包创建的?
    lloovve
        2
    lloovve  
       Feb 23, 2022
    打印出来的是 channel 过来的数据吧,不是携程数
    pixelpig
        3
    pixelpig  
       Feb 23, 2022
    可以用 pprof 分析一下协程上下文,就知道是哪里创建的
    janxin
        4
    janxin  
       Feb 23, 2022
    但是问题是都进程退出了,是不是泄漏了不是很重要...
    luxcgo
        5
    luxcgo  
    OP
       Feb 23, 2022
    @CEBBCAT 经过分析,是的
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2535 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 115ms · UTC 00:30 · PVG 08:30 · LAX 17:30 · JFK 20:30
    ♥ Do have faith in what you're doing.