Skip to content

Commit 849f000

Browse files
Pantanijulienrbrt
authored andcommitted
fix: race conditions in the plugin logic (#4091)
* fix race condition for unit tests * add changelog * increase TestScaffoldedTests timeout --------- Co-authored-by: Pantani <Pantani>
1 parent bce7055 commit 849f000

File tree

6 files changed

+12
-4
lines changed

6 files changed

+12
-4
lines changed

changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
- [#3969](https://github.com/ignite/cli/pull/3969) Get first config validator using a getter to avoid index errors
3333
- [#4000](https://github.com/ignite/cli/pull/4000) Run all dry runners before the wet run in the `xgenny` pkg
3434
- [#4086](https://github.com/ignite/cli/pull/4086) Retry to get the IBC balance if it fails the first time
35+
- [#4091](https://github.com/ignite/cli/pull/4091) Fix race conditions in the plugin logic
3536
- [#4096](https://github.com/ignite/cli/pull/4096) Add new reserved names module and remove duplicated genesis order
3637

3738
## [`v28.3.0`](https://github.com/ignite/cli/releases/tag/v28.3.0)

ignite/internal/plugin/execute.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,12 @@ func Execute(ctx context.Context, path string, args []string, options ...plugin.
3535
if err != nil {
3636
// Extract the rpc status message and create a simple error from it.
3737
// We don't want Execute to return rpc errors.
38-
err = errors.New(status.Convert(err).Message())
38+
return "", errors.New(status.Convert(err).Message())
3939
}
4040
// NOTE(tb): This pause gives enough time for go-plugin to sync the
4141
// output from stdout/stderr of the plugin. Without that pause, this
4242
// output can be discarded and absent from buf.
4343
time.Sleep(100 * time.Millisecond)
44+
plugins[0].KillClient()
4445
return buf.String(), err
4546
}

ignite/services/plugin/protocol.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package plugin
22

33
import (
44
"context"
5+
"sync"
56

67
hplugin "github.com/hashicorp/go-plugin"
78
"google.golang.org/grpc"
@@ -108,19 +109,24 @@ func (c client) ExecuteHookCleanUp(ctx context.Context, h *ExecutedHook, api Cli
108109
func (c client) startClientAPIServer(api ClientAPI) (uint32, func()) {
109110
var (
110111
srv *grpc.Server
112+
m sync.Mutex
111113
brokerID = c.broker.NextId()
112114
)
113115

114116
go c.broker.AcceptAndServe(brokerID, func(opts []grpc.ServerOption) *grpc.Server {
117+
m.Lock()
118+
defer m.Unlock()
115119
srv = grpc.NewServer(opts...)
116120
v1.RegisterClientAPIServiceServer(srv, &clientAPIServer{impl: api})
117121
return srv
118122
})
119123

120124
stop := func() {
125+
m.Lock()
121126
if srv != nil {
122127
srv.Stop()
123128
}
129+
m.Unlock()
124130
}
125131

126132
return brokerID, stop

ignite/services/plugin/scaffold_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ func TestScaffoldedTests(t *testing.T) {
5252
// Act
5353
err := gocmd.Test(ctx, path, []string{
5454
"-timeout",
55-
"5m",
55+
"10m",
5656
"-run",
5757
"^TestBar$",
5858
})

scripts/test-coverage

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#!/bin/bash
22
set -e -x
33

4-
go test -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... $(go list github.com/ignite/cli/v29/ignite/...)
4+
go test -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=./... $(go list github.com/ignite/cli/v29/ignite/...)
55

66
# append "||true" to grep so if no match the return code stays 0
77
excludelist="$(find ./ -type f -name '*.go' | xargs grep -l 'DONTCOVER' || true)"

scripts/test-integration

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
#!/bin/bash
22

3-
go test -v -timeout 120m github.com/ignite/cli/v29/integration/...
3+
go test -v -timeout 30m github.com/ignite/cli/v29/integration/...

0 commit comments

Comments
 (0)