mirror of
https://github.com/zrepl/zrepl.git
synced 2025-02-18 03:11:55 +01:00
cmd close RPC with timeout
This commit is contained in:
parent
48a4e8033a
commit
b1a3a57623
36
cmd/main.go
36
cmd/main.go
@ -29,9 +29,11 @@ func main() {
|
|||||||
|
|
||||||
defer func() {
|
defer func() {
|
||||||
e := recover()
|
e := recover()
|
||||||
defaultLog.Printf("panic:\n%s\n\n", debug.Stack())
|
if e != nil {
|
||||||
defaultLog.Printf("error: %t %s", e, e)
|
defaultLog.Printf("panic:\n%s\n\n", debug.Stack())
|
||||||
os.Exit(1)
|
defaultLog.Printf("error: %t %s", e, e)
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
}()
|
}()
|
||||||
|
|
||||||
app := cli.NewApp()
|
app := cli.NewApp()
|
||||||
@ -191,6 +193,32 @@ func doRun(c *cli.Context) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func closeRPCWithTimeout(log Logger, remote rpc.RPCRequester, timeout time.Duration, goodbye string) {
|
||||||
|
log.Printf("closing rpc connection")
|
||||||
|
|
||||||
|
ch := make(chan error)
|
||||||
|
go func() {
|
||||||
|
ch <- remote.CloseRequest(rpc.CloseRequest{goodbye})
|
||||||
|
}()
|
||||||
|
|
||||||
|
var err error
|
||||||
|
select {
|
||||||
|
case <-time.After(timeout):
|
||||||
|
err = fmt.Errorf("timeout exceeded (%s)", timeout)
|
||||||
|
case closeRequestErr := <-ch:
|
||||||
|
err = closeRequestErr
|
||||||
|
}
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error closing connection: %s", err)
|
||||||
|
err = remote.ForceClose()
|
||||||
|
if err != nil {
|
||||||
|
log.Printf("error force-closing connection: %s", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
func doPull(pull Pull, c *cli.Context, log jobrun.Logger) (err error) {
|
func doPull(pull Pull, c *cli.Context, log jobrun.Logger) (err error) {
|
||||||
|
|
||||||
if lt, ok := pull.From.Transport.(LocalTransport); ok {
|
if lt, ok := pull.From.Transport.(LocalTransport); ok {
|
||||||
@ -208,7 +236,7 @@ func doPull(pull Pull, c *cli.Context, log jobrun.Logger) (err error) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer remote.Close()
|
defer closeRPCWithTimeout(log, remote, time.Second*10, "")
|
||||||
|
|
||||||
fsr := rpc.FilesystemRequest{
|
fsr := rpc.FilesystemRequest{
|
||||||
Direction: rpc.DirectionPull,
|
Direction: rpc.DirectionPull,
|
||||||
|
Loading…
Reference in New Issue
Block a user