1
0
mirror of https://github.com/Mrs4s/go-cqhttp.git synced 2025-05-05 03:23:49 +08:00

deal with pipe close error

This commit is contained in:
povsister 2021-06-26 14:53:19 +08:00
parent e2cafbd7d6
commit 752c82e8d6
No known key found for this signature in database
GPG Key ID: E6D134210265CBC3
2 changed files with 8 additions and 0 deletions

View File

@ -9,6 +9,7 @@ import (
"syscall" "syscall"
) )
// SetupMainSignalHandler is for main to use at last
func SetupMainSignalHandler() <-chan struct{} { func SetupMainSignalHandler() <-chan struct{} {
mainOnce.Do(func() { mainOnce.Do(func() {
mc := make(chan os.Signal, 2) mc := make(chan os.Signal, 2)

View File

@ -3,9 +3,12 @@
package global package global
import ( import (
"errors"
"fmt" "fmt"
"net"
"os" "os"
"os/signal" "os/signal"
"strings"
"sync" "sync"
"syscall" "syscall"
"time" "time"
@ -20,6 +23,7 @@ var (
} }
) )
// SetupMainSignalHandler is for main to use at last
func SetupMainSignalHandler() <-chan struct{} { func SetupMainSignalHandler() <-chan struct{} {
mainOnce.Do(func() { mainOnce.Do(func() {
// for stack trace collecting on windows // for stack trace collecting on windows
@ -38,6 +42,9 @@ func SetupMainSignalHandler() <-chan struct{} {
for { for {
c, err := pipe.Accept() c, err := pipe.Accept()
if err != nil { if err != nil {
if errors.Is(err, net.ErrClosed) || strings.Contains(err.Error(), "closed") {
return
}
log.Errorf("accept named pipe 失败: %v", err) log.Errorf("accept named pipe 失败: %v", err)
continue continue
} }