Skip to content

Commit

Permalink
improve skysocks-client logic for close signal
Browse files Browse the repository at this point in the history
  • Loading branch information
mrpalide committed Mar 21, 2024
1 parent aa8b32c commit dc625f1
Showing 1 changed file with 13 additions and 10 deletions.
23 changes: 13 additions & 10 deletions cmd/apps/skysocks-client/commands/skysocks-client.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"context"
"errors"
"fmt"
"io"
"log"
"net"
"net/http"
Expand Down Expand Up @@ -103,15 +102,18 @@ var RootCmd = &cobra.Command{
setAppErr(appCl, err)
os.Exit(1)
}

var closeSignal bool
if runtime.GOOS == "windows" {
ipcClient, err := ipc.StartClient(visorconfig.SkysocksName, nil)
if err != nil {
setAppErr(appCl, err)
print(fmt.Sprintf("Error creating ipc server for skysocks: %v\n", err))
os.Exit(1)
}
go client.ListenIPC(ipcClient)
go func() {
client.ListenIPC(ipcClient)
closeSignal = true
}()
} else {
termCh := make(chan os.Signal, 1)
signal.Notify(termCh, os.Interrupt)
Expand All @@ -121,6 +123,7 @@ var RootCmd = &cobra.Command{
print(fmt.Sprintf("%v\n", err))
os.Exit(1)
}
closeSignal = true
}()
}

Expand All @@ -131,13 +134,13 @@ var RootCmd = &cobra.Command{
go httpProxy(httpCtx, httpAddr, addr)
}
defer httpCancel()

if err := client.ListenAndServe(addr); err != nil {
print(fmt.Sprintf("Error serving proxy client: %v\n", err))
}
// need to filter this out, cause usually client failure means app conn is already closed
if err := conn.Close(); err != nil && err != io.ErrClosedPipe {
print(fmt.Sprintf("Error closing app conn: %v\n", err))
for {
if err := client.ListenAndServe(addr); err != nil {
print(fmt.Sprintf("Error serving proxy client: %v\n", err))
}
if closeSignal {
break
}
}
},
}
Expand Down

0 comments on commit dc625f1

Please sign in to comment.