From 599c65adb25f1f80d3ecd03a176913f760f6e549 Mon Sep 17 00:00:00 2001 From: Maarten Everts Date: Fri, 4 Sep 2020 16:10:28 +0200 Subject: [PATCH] Wait for response on socket when sending It appears that signald doesn't like not being able to send something back on the socket. --- cmd/signald-cli/cmd/send.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/cmd/signald-cli/cmd/send.go b/cmd/signald-cli/cmd/send.go index dbba3d7..a6132bd 100644 --- a/cmd/signald-cli/cmd/send.go +++ b/cmd/signald-cli/cmd/send.go @@ -19,6 +19,7 @@ import ( "log" "github.com/spf13/cobra" + "time" "git.callpipe.com/finn/signald-go/signald" "git.callpipe.com/finn/signald-go/signald/client-protocol/v1" @@ -59,6 +60,20 @@ var sendCmd = &cobra.Command{ request.AttachmentFilenames = []string{attachment} } s.SendRequest(request) + + timeout := 10 + + // Wait for the response + c := make(chan signald.Response) + + go s.Listen(c) + select { + case <-c: + log.Println("Ok.") + case <-time.After(1 * time.Second): + // But timeout after a while + log.Fatalf("Timeout after %d seconds\n", timeout) + } }, }