From 73941a3066d35598cedaeaf858ab7fbf857fe3f9 Mon Sep 17 00:00:00 2001 From: Austin Schey Date: Mon, 26 Apr 2021 04:43:42 -0500 Subject: [PATCH] Immediately retry a disconnected grpc connection before attempting to send a request (#61) * update wails and go versions, remove mewn dependency * retry connection on request * update changelog, revert other changes * formatting * use once instead of on for single use callback --- .github/workflows/package.yml | 1 - CHANGELOG.md | 1 + internal/app/api.go | 19 +++++++++++++++++-- 3 files changed, 18 insertions(+), 3 deletions(-) diff --git a/.github/workflows/package.yml b/.github/workflows/package.yml index e64a73a..6d77b87 100644 --- a/.github/workflows/package.yml +++ b/.github/workflows/package.yml @@ -174,4 +174,3 @@ jobs: asset_path: Wombat_${{ steps.version.outputs.tag }}_Windows_x86_64.zip/Wombat_${{ steps.version.outputs.tag }}_Windows_x86_64.zip asset_name: Wombat_${{ steps.version.outputs.tag }}_Windows_x86_64.zip asset_content_type: application/octet-stream - diff --git a/CHANGELOG.md b/CHANGELOG.md index de47b85..7e1cb5f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added - Support export/import request to/from grpcurl command. Thanks to [@devkanro](https://github.com/devkanro) & [@iou90](https://github.com/iou90) +- Immediately retry a disconnected grpc connection before attempting to send a request. Thanks to [@aschey](https://github.com/aschey) ### Fixed - Update dependencies to fix an issue with newer versions of webkit2gtk. Thanks to [@aschey](https://github.com/aschey) diff --git a/internal/app/api.go b/internal/app/api.go index 0a1039c..f44247a 100644 --- a/internal/app/api.go +++ b/internal/app/api.go @@ -709,6 +709,19 @@ func fieldViewsFromDesc(fds protoreflect.FieldDescriptors, isOneof bool, cd *cyc return fields, nil } +func (a *api) RetryConnection() { + state := a.client.conn.GetState() + if state == connectivity.TransientFailure || state == connectivity.Shutdown { + // State is currently disconnected. Do a quick retry in case the server restarted recently. + a.client.conn.ResetConnectBackoff() + stateChanged := make(chan bool) + waitForStateChange := func(data ...interface{}) { stateChanged <- true } + a.runtime.Events.Once(eventClientStateChanged, waitForStateChange) + // Wait for at least one retry to complete before continuing + <-stateChanged + } +} + func (a *api) Send(method string, rawJSON []byte, rawHeaders interface{}) (rerr error) { defer func() { if rerr != nil { @@ -718,6 +731,8 @@ func (a *api) Send(method string, rawJSON []byte, rawHeaders interface{}) (rerr } }() + a.RetryConnection() + md, err := a.getMethodDesc(method) if err != nil { return err @@ -1033,8 +1048,8 @@ func (a *api) ImportCommand(kind string, command string) (rerr error) { return err } - return a.emitServicesSelect("/" + args.Method, args.Data, args.Metadata) + return a.emitServicesSelect("/"+args.Method, args.Data, args.Metadata) } return nil -} \ No newline at end of file +}