From 42b2c0bc6d51e6c781387248840b9dc477249cc5 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Fri, 4 Aug 2023 16:37:45 +0530 Subject: [PATCH 01/11] fix: race condition in rendezvous test code --- Makefile | 5 ++++- waku/v2/rendezvous/rendezvous.go | 2 +- waku/v2/rendezvous/rendezvous_test.go | 6 ++++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index 3d2f1867..9f1ae11d 100644 --- a/Makefile +++ b/Makefile @@ -50,6 +50,9 @@ all: build deps: lint-install +build-with-race: + ${GOBIN} build -race -tags="${BUILD_TAGS}" $(BUILD_FLAGS) -o build/waku ./cmd/waku + build: ${GOBIN} build -tags="${BUILD_TAGS}" $(BUILD_FLAGS) -o build/waku ./cmd/waku @@ -70,7 +73,7 @@ lint: @golangci-lint --exclude=SA1019 run ./... --deadline=5m test: - ${GOBIN} test -timeout 300s ./waku/... -coverprofile=${GO_TEST_OUTFILE}.tmp + ${GOBIN} test -race -timeout 300s ./waku/... -coverprofile=${GO_TEST_OUTFILE}.tmp cat ${GO_TEST_OUTFILE}.tmp | grep -v ".pb.go" > ${GO_TEST_OUTFILE} ${GOBIN} tool cover -html=${GO_TEST_OUTFILE} -o ${GO_HTML_COV} diff --git a/waku/v2/rendezvous/rendezvous.go b/waku/v2/rendezvous/rendezvous.go index 606cc6a7..4d4550b3 100644 --- a/waku/v2/rendezvous/rendezvous.go +++ b/waku/v2/rendezvous/rendezvous.go @@ -91,7 +91,7 @@ func (r *Rendezvous) DiscoverShard(ctx context.Context, rp *RendezvousPoint, clu r.DiscoverWithNamespace(ctx, namespace, rp, numPeers) } -// DiscoverWithNamespace is uded to find a number of peers using a custom namespace (usually a pubsub topic) +// DiscoverWithNamespace is used to find a number of peers using a custom namespace (usually a pubsub topic) func (r *Rendezvous) DiscoverWithNamespace(ctx context.Context, namespace string, rp *RendezvousPoint, numPeers int) { rendezvousClient := rvs.NewRendezvousClient(r.host, rp.id) diff --git a/waku/v2/rendezvous/rendezvous_test.go b/waku/v2/rendezvous/rendezvous_test.go index 8310be3f..671d5a09 100644 --- a/waku/v2/rendezvous/rendezvous_test.go +++ b/waku/v2/rendezvous/rendezvous_test.go @@ -5,6 +5,7 @@ import ( "crypto/rand" "database/sql" "fmt" + "sync" "testing" "time" @@ -19,11 +20,14 @@ import ( ) type PeerConn struct { + sync.RWMutex ch <-chan peermanager.PeerData } func (p *PeerConn) Subscribe(ctx context.Context, ch <-chan peermanager.PeerData) { + p.Lock() p.ch = ch + p.Unlock() } func NewPeerConn() *PeerConn { @@ -98,6 +102,8 @@ func TestRendezvous(t *testing.T) { time.Sleep(500 * time.Millisecond) timer := time.After(3 * time.Second) + myPeerConnector.RLock() + defer myPeerConnector.RUnlock() select { case <-timer: require.Fail(t, "no peer discovered") From 884f65ecdf5383da99d47378499246dd04fb2b56 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Fri, 4 Aug 2023 17:19:53 +0530 Subject: [PATCH 02/11] fix: noise protocol channel close race condition --- waku/v2/protocol/noise/pairing_relay_messenger.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/waku/v2/protocol/noise/pairing_relay_messenger.go b/waku/v2/protocol/noise/pairing_relay_messenger.go index e5554d50..edb14192 100644 --- a/waku/v2/protocol/noise/pairing_relay_messenger.go +++ b/waku/v2/protocol/noise/pairing_relay_messenger.go @@ -95,6 +95,7 @@ func (r *NoiseWakuRelay) Subscribe(ctx context.Context, contentTopic string) <-c for { select { case <-ctx.Done(): + close(sub.msgChan) return case env := <-sub.broadcastSub.Ch: if env == nil { @@ -137,7 +138,6 @@ func (r *NoiseWakuRelay) Stop() { for _, contentTopicSubscriptions := range r.subscriptionChPerContentTopic { for _, c := range contentTopicSubscriptions { c.broadcastSub.Unsubscribe() - close(c.msgChan) } } } From 87a7501166548ddf646fb956cd8fe0f8fc412999 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Fri, 4 Aug 2023 17:24:27 +0530 Subject: [PATCH 03/11] chore:dependency fixes --- examples/basic2/go.mod | 8 ++++---- examples/basic2/go.sum | 16 ++++++++-------- examples/noise/go.mod | 8 ++++---- examples/noise/go.sum | 16 ++++++++-------- 4 files changed, 24 insertions(+), 24 deletions(-) diff --git a/examples/basic2/go.mod b/examples/basic2/go.mod index 6a496f67..335c995b 100644 --- a/examples/basic2/go.mod +++ b/examples/basic2/go.mod @@ -107,10 +107,10 @@ require ( github.com/tklauser/numcpus v0.2.2 // indirect github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 // indirect github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 // indirect - github.com/waku-org/go-zerokit-rln v0.1.13-0.20230726180145-0496a42e60fb // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230726162122-13b66414cd5b // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230726162204-c48a56712ef0 // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230726162310-d761ca9911d8 // indirect + github.com/waku-org/go-zerokit-rln v0.1.13-0.20230803113701-ea89e5d7eedb // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 // indirect github.com/wk8/go-ordered-map v1.0.0 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/examples/basic2/go.sum b/examples/basic2/go.sum index 95f2f425..b29e5ab3 100644 --- a/examples/basic2/go.sum +++ b/examples/basic2/go.sum @@ -658,14 +658,14 @@ github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 h1:xwY0kW5XZF github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98/go.mod h1:eBHgM6T4EG0RZzxpxKy+rGz/6Dw2Nd8DWxS0lm9ESDw= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0e1h+p84yBp0IN7AqgbZlV7lgFBjm214lgSOE7CeJmE= github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04= -github.com/waku-org/go-zerokit-rln v0.1.13-0.20230726180145-0496a42e60fb h1:pxPRTh2DWCPCC5dhFisHuBCm1k54fMtR8VR6hUWD734= -github.com/waku-org/go-zerokit-rln v0.1.13-0.20230726180145-0496a42e60fb/go.mod h1:QYTnrByLh6OXvMzSvPNs5aykT/w4fQb4krGcZfKgSZw= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230726162122-13b66414cd5b h1:wWs8b91SVrxYy37gdNnFDCbjv1hMUHMTwaJUktyjrJE= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230726162122-13b66414cd5b/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230726162204-c48a56712ef0 h1:JU5aMzRFeyG/DOiMwLy3F1AMuuXjzPrUKZpW72kAHxE= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230726162204-c48a56712ef0/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230726162310-d761ca9911d8 h1:pQmTryFdSQuUe8dxt/dHgEfRdLwqf1DEGeReuMcJ9Yg= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230726162310-d761ca9911d8/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.13-0.20230803113701-ea89e5d7eedb h1:f1UbFvroZbAul1HTlzM4ZGgjQ3mtn0bW8Jvk7XZQ5V4= +github.com/waku-org/go-zerokit-rln v0.1.13-0.20230803113701-ea89e5d7eedb/go.mod h1:1S6g1KXC45HkDXhIWD9+mdAs9fdyzQy8gtmw4RLjVcM= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e h1:Ad0rJod5F1FuYCJ8SUB/bQZsQwirNHQRE0IcaVloxZo= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a h1:10cre+P76QvnLeyeCVAM8WDbUCri/y5xY3LtwI9Y5DE= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 h1:GseAHwGMixJ2zlY1kFYr3z1Ts0dREIYbgW4yIji9Ksw= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/wk8/go-ordered-map v1.0.0 h1:BV7z+2PaK8LTSd/mWgY12HyMAo5CEgkHqbkVq2thqr8= github.com/wk8/go-ordered-map v1.0.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk= diff --git a/examples/noise/go.mod b/examples/noise/go.mod index 19bb9367..0f90ae61 100644 --- a/examples/noise/go.mod +++ b/examples/noise/go.mod @@ -109,10 +109,10 @@ require ( github.com/tklauser/numcpus v0.2.2 // indirect github.com/waku-org/go-discover v0.0.0-20221209174356-61c833f34d98 // indirect github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 // indirect - github.com/waku-org/go-zerokit-rln v0.1.12 // indirect - github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331231302-258cacb91327 // indirect - github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230331223149-f90e66aebb0d // indirect - github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230331181847-cba74520bae9 // indirect + github.com/waku-org/go-zerokit-rln v0.1.13-0.20230803113701-ea89e5d7eedb // indirect + github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e // indirect + github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a // indirect + github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 // indirect github.com/wk8/go-ordered-map v1.0.0 // indirect go.opencensus.io v0.24.0 // indirect go.uber.org/atomic v1.11.0 // indirect diff --git a/examples/noise/go.sum b/examples/noise/go.sum index b1ab21d9..103c85a0 100644 --- a/examples/noise/go.sum +++ b/examples/noise/go.sum @@ -660,14 +660,14 @@ github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7 h1:0 github.com/waku-org/go-libp2p-rendezvous v0.0.0-20230628220917-7b4e5ae4c0e7/go.mod h1:pFvOZ9YTFsW0o5zJW7a0B5tr1owAijRWJctXJ2toL04= github.com/waku-org/go-noise v0.0.4 h1:ZfQDcCw8pazm89EBl5SXY7GGAnzDQb9AHFXlw3Ktbvk= github.com/waku-org/go-noise v0.0.4/go.mod h1:+PWRfs2eSOVwKrPcQlfhwDngSh3faL/1QoxvoqggEKc= -github.com/waku-org/go-zerokit-rln v0.1.12 h1:66+tU6sTlmUpuUlEv7kCFOGZ37MwZYFJBXHcm8QquwU= -github.com/waku-org/go-zerokit-rln v0.1.12/go.mod h1:MUW+wB6Yj7UBMdZrhko7oHfUZeY2wchggXYjpUiMoac= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331231302-258cacb91327 h1:Q5XQqo+PEmvrybT8D7BEsKCwIYDi80s+00Q49cfm9Gs= -github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230331231302-258cacb91327/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230331223149-f90e66aebb0d h1:Kcg85Y2xGU6hqZ/kMfkLQF2jAog8vt+tw1/VNidzNtE= -github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230331223149-f90e66aebb0d/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230331181847-cba74520bae9 h1:u+YUlWDltHiK5upSb7M6mStc84zdc4vTCNNOz7R5RaY= -github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230331181847-cba74520bae9/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= +github.com/waku-org/go-zerokit-rln v0.1.13-0.20230803113701-ea89e5d7eedb h1:f1UbFvroZbAul1HTlzM4ZGgjQ3mtn0bW8Jvk7XZQ5V4= +github.com/waku-org/go-zerokit-rln v0.1.13-0.20230803113701-ea89e5d7eedb/go.mod h1:1S6g1KXC45HkDXhIWD9+mdAs9fdyzQy8gtmw4RLjVcM= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e h1:Ad0rJod5F1FuYCJ8SUB/bQZsQwirNHQRE0IcaVloxZo= +github.com/waku-org/go-zerokit-rln-apple v0.0.0-20230803113401-9a7ef94d120e/go.mod h1:KYykqtdApHVYZ3G0spwMnoxc5jH5eI3jyO9SwsSfi48= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a h1:10cre+P76QvnLeyeCVAM8WDbUCri/y5xY3LtwI9Y5DE= +github.com/waku-org/go-zerokit-rln-arm v0.0.0-20230801152407-8101ff87ee0a/go.mod h1:7cSGUoGVIla1IpnChrLbkVjkYgdOcr7rcifEfh4ReR4= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5 h1:GseAHwGMixJ2zlY1kFYr3z1Ts0dREIYbgW4yIji9Ksw= +github.com/waku-org/go-zerokit-rln-x86_64 v0.0.0-20230801140722-0a4e68d0b8f5/go.mod h1:+LeEYoW5/uBUTVjtBGLEVCUe9mOYAlu5ZPkIxLOSr5Y= github.com/willf/bitset v1.1.3/go.mod h1:RjeCKbqT1RxIR/KWY6phxZiaY1IyutSBfGjNPySAYV4= github.com/wk8/go-ordered-map v1.0.0 h1:BV7z+2PaK8LTSd/mWgY12HyMAo5CEgkHqbkVq2thqr8= github.com/wk8/go-ordered-map v1.0.0/go.mod h1:9ZIbRunKbuvfPKyBP1SIKLcXNlv74YCOZ3t3VTS6gRk= From 22398b286898f2b616c46ae1b5c6b0518aaddcfb Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Sat, 5 Aug 2023 08:00:04 +0530 Subject: [PATCH 04/11] fix:race in filter peer subscription map iteration and deletion --- waku/v2/protocol/filter/client.go | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/waku/v2/protocol/filter/client.go b/waku/v2/protocol/filter/client.go index 81ac8733..39b8d65a 100644 --- a/waku/v2/protocol/filter/client.go +++ b/waku/v2/protocol/filter/client.go @@ -317,10 +317,6 @@ func (wf *WakuFilterLightnode) cleanupSubscriptions(peerID peer.ID, contentFilte wf.subscriptions.items[peerID].subscriptionsPerTopic[contentFilter.Topic] = subscriptionDetailList } - if len(wf.subscriptions.items[peerID].subscriptionsPerTopic) == 0 { - delete(wf.subscriptions.items, peerID) - } - } // Unsubscribe is used to stop receiving messages from a peer that match a content filter @@ -344,12 +340,12 @@ func (wf *WakuFilterLightnode) Unsubscribe(ctx context.Context, contentFilter Co localWg := sync.WaitGroup{} resultChan := make(chan WakuFilterPushResult, len(wf.subscriptions.items)) - + var peersUnsubscribed []peer.ID for peerID := range wf.subscriptions.items { if params.selectedPeer != "" && peerID != params.selectedPeer { continue } - + peersUnsubscribed = append(peersUnsubscribed, peerID) localWg.Add(1) go func(peerID peer.ID) { defer localWg.Done() @@ -379,7 +375,11 @@ func (wf *WakuFilterLightnode) Unsubscribe(ctx context.Context, contentFilter Co localWg.Wait() close(resultChan) - + for _, peerID := range peersUnsubscribed { + if len(wf.subscriptions.items[peerID].subscriptionsPerTopic) == 0 { + delete(wf.subscriptions.items, peerID) + } + } return resultChan, nil } From 20040f2e9b566b48cd568b0849f58d106a360315 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Sat, 5 Aug 2023 08:03:19 +0530 Subject: [PATCH 05/11] fix: data race in filter unsubscribe --- waku/v2/protocol/filter/client.go | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/waku/v2/protocol/filter/client.go b/waku/v2/protocol/filter/client.go index 39b8d65a..ca7977b5 100644 --- a/waku/v2/protocol/filter/client.go +++ b/waku/v2/protocol/filter/client.go @@ -407,11 +407,14 @@ func (wf *WakuFilterLightnode) UnsubscribeAll(ctx context.Context, opts ...Filte localWg := sync.WaitGroup{} resultChan := make(chan WakuFilterPushResult, len(wf.subscriptions.items)) + var peersUnsubscribed []peer.ID for peerID := range wf.subscriptions.items { if params.selectedPeer != "" && peerID != params.selectedPeer { continue } + peersUnsubscribed = append(peersUnsubscribed, peerID) + localWg.Add(1) go func(peerID peer.ID) { defer localWg.Done() @@ -423,9 +426,6 @@ func (wf *WakuFilterLightnode) UnsubscribeAll(ctx context.Context, opts ...Filte if err != nil { wf.log.Error("could not unsubscribe from peer", logging.HostID("peerID", peerID), zap.Error(err)) } - - delete(wf.subscriptions.items, peerID) - resultChan <- WakuFilterPushResult{ Err: err, PeerID: peerID, @@ -435,6 +435,10 @@ func (wf *WakuFilterLightnode) UnsubscribeAll(ctx context.Context, opts ...Filte localWg.Wait() close(resultChan) - + for _, peerID := range peersUnsubscribed { + if len(wf.subscriptions.items[peerID].subscriptionsPerTopic) == 0 { + delete(wf.subscriptions.items, peerID) + } + } return resultChan, nil } From baeaa1dd556208bf508f69a90529678166ee818b Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Mon, 7 Aug 2023 14:42:48 +0530 Subject: [PATCH 06/11] fix: data race in peer connector --- waku/v2/peermanager/discovery_connector.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/waku/v2/peermanager/discovery_connector.go b/waku/v2/peermanager/discovery_connector.go index d41d8eb7..040b53e0 100644 --- a/waku/v2/peermanager/discovery_connector.go +++ b/waku/v2/peermanager/discovery_connector.go @@ -301,7 +301,9 @@ func (c *PeerConnectionStrategy) dialPeers(ctx context.Context) { c.wg.Add(1) go func(pi peer.AddrInfo) { defer c.wg.Done() + c.RLock() ctx, cancel := context.WithTimeout(c.workerCtx, c.dialTimeout) + c.RUnlock() defer cancel() err := c.host.Connect(ctx, pi) if err != nil && !errors.Is(err, context.Canceled) { From af7471d15867640444397c0800771eb95ecf1533 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Mon, 7 Aug 2023 15:01:44 +0530 Subject: [PATCH 07/11] fix:during unsubscribeAll, remove peer without any checks --- waku/v2/protocol/filter/client.go | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/waku/v2/protocol/filter/client.go b/waku/v2/protocol/filter/client.go index ca7977b5..9763b3de 100644 --- a/waku/v2/protocol/filter/client.go +++ b/waku/v2/protocol/filter/client.go @@ -436,9 +436,7 @@ func (wf *WakuFilterLightnode) UnsubscribeAll(ctx context.Context, opts ...Filte localWg.Wait() close(resultChan) for _, peerID := range peersUnsubscribed { - if len(wf.subscriptions.items[peerID].subscriptionsPerTopic) == 0 { - delete(wf.subscriptions.items, peerID) - } + delete(wf.subscriptions.items, peerID) } return resultChan, nil } From 6429af9ca7577c6b2c9bbdb98f3a4e8334ac29fc Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Mon, 7 Aug 2023 21:20:36 +0530 Subject: [PATCH 08/11] chore: disable -race by default and create a new make target --- Makefile | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 9f1ae11d..0b764dcb 100644 --- a/Makefile +++ b/Makefile @@ -72,8 +72,11 @@ lint: @echo "lint" @golangci-lint --exclude=SA1019 run ./... --deadline=5m +test-with-race: + ${GOBIN} test -race -timeout 300s ./waku/... + test: - ${GOBIN} test -race -timeout 300s ./waku/... -coverprofile=${GO_TEST_OUTFILE}.tmp + ${GOBIN} test -timeout 300s ./waku/... -coverprofile=${GO_TEST_OUTFILE}.tmp cat ${GO_TEST_OUTFILE}.tmp | grep -v ".pb.go" > ${GO_TEST_OUTFILE} ${GOBIN} tool cover -html=${GO_TEST_OUTFILE} -o ${GO_HTML_COV} @@ -187,3 +190,5 @@ test-onchain: BUILD_TAGS += include_onchain_tests test-onchain: ${GOBIN} test -v -count 1 -tags="${BUILD_TAGS}" github.com/waku-org/go-waku/waku/v2/protocol/rln +test-onchain-with-race: + ${GOBIN} test -race -v -count 1 -tags="${BUILD_TAGS}" github.com/waku-org/go-waku/waku/v2/protocol/rln \ No newline at end of file From 7c632e40c0b4faaa17b7137aa7bc0a10d5319d00 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Mon, 7 Aug 2023 21:21:12 +0530 Subject: [PATCH 09/11] chore: add new jenkins job file to run tests with race flag --- ci/Jenkinsfile.testsWithRace | 74 ++++++++++++++++++++++++++++++++++++ 1 file changed, 74 insertions(+) create mode 100644 ci/Jenkinsfile.testsWithRace diff --git a/ci/Jenkinsfile.testsWithRace b/ci/Jenkinsfile.testsWithRace new file mode 100644 index 00000000..b234bf59 --- /dev/null +++ b/ci/Jenkinsfile.testsWithRace @@ -0,0 +1,74 @@ +library 'status-jenkins-lib@v1.7.0' + +pipeline { + agent { + label 'linux && nix-2.11 && x86_64' + } + + options { + timestamps() + disableConcurrentBuilds() + /* Prevent Jenkins jobs from running forever */ + timeout(time: 30, unit: 'MINUTES') + /* Go requires a certain directory structure */ + checkoutToSubdirectory('src/github.com/waku-org/go-waku') + buildDiscarder(logRotator( + numToKeepStr: '10', + daysToKeepStr: '30', + )) + } + + environment { + TARGET = 'tests-with-race' + REPO = "${env.WORKSPACE}/src/github.com/waku-org/go-waku" + GOCACHE = "${env.WORKSPACE_TMP}/go-build" + GOPATH = "${env.WORKSPACE}/go" + PATH = "${env.PATH}:${env.GOPATH}/bin" + /* Necesary to avoid cache poisoning by other builds. */ + GOLANGCI_LINT_CACHE = "${env.WORKSPACE_TMP}/golangci-lint" + /* Ganache config */ + GANACHE_RPC_PORT = "${8989 + env.EXECUTOR_NUMBER.toInteger()}" + GANACHE_MNEMONIC = 'swim relax risk shy chimney please usual search industry board music segment' + } + + stages { + stage('Test') { + steps { script { dir(env.REPO) { + nix.develop('make test-with-race', pure: false) + } } } + } + + stage('Ganache') { + steps { script { + ganache = docker.image( + 'trufflesuite/ganache:v7.4.1' + ).run( + "-p 127.0.0.1:${env.GANACHE_RPC_PORT}:8545", + "-m='${GANACHE_MNEMONIC}'" + ) + } } + } + + stage('On-chain tests') { + environment { + GANACHE_NETWORK_RPC_URL = "ws://localhost:${env.GANACHE_RPC_PORT}" + } + steps { script { dir(env.REPO) { + nix.develop('make test-onchain-with-race', pure: false) + } } } + } + } + post { + always { script { /* No artifact but a PKG_URL is necessary. */ + env.PKG_URL = "${currentBuild.absoluteUrl}consoleText" + } } + success { script { github.notifyPR(true) } } + failure { script { github.notifyPR(false) } } + cleanup { script { + cleanWs() + catchError { + ganache.stop() + } + } } + } +} From 65f26978f922180e78de3ac1164edcc3927f1046 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Tue, 8 Aug 2023 10:16:54 +0530 Subject: [PATCH 10/11] chore: address review comments --- ci/Jenkinsfile.tests | 2 +- ci/Jenkinsfile.testsWithRace | 10 ++++++---- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/ci/Jenkinsfile.tests b/ci/Jenkinsfile.tests index c08fcf43..4cf4b82c 100644 --- a/ci/Jenkinsfile.tests +++ b/ci/Jenkinsfile.tests @@ -26,7 +26,7 @@ pipeline { PATH = "${env.PATH}:${env.GOPATH}/bin" /* Necesary to avoid cache poisoning by other builds. */ GOLANGCI_LINT_CACHE = "${env.WORKSPACE_TMP}/golangci-lint" - /* Ganache config */ + /* Ganache config */ GANACHE_RPC_PORT = "${8989 + env.EXECUTOR_NUMBER.toInteger()}" GANACHE_MNEMONIC = 'swim relax risk shy chimney please usual search industry board music segment' } diff --git a/ci/Jenkinsfile.testsWithRace b/ci/Jenkinsfile.testsWithRace index b234bf59..d16e4603 100644 --- a/ci/Jenkinsfile.testsWithRace +++ b/ci/Jenkinsfile.testsWithRace @@ -26,19 +26,21 @@ pipeline { PATH = "${env.PATH}:${env.GOPATH}/bin" /* Necesary to avoid cache poisoning by other builds. */ GOLANGCI_LINT_CACHE = "${env.WORKSPACE_TMP}/golangci-lint" - /* Ganache config */ + /* Ganache config */ GANACHE_RPC_PORT = "${8989 + env.EXECUTOR_NUMBER.toInteger()}" - GANACHE_MNEMONIC = 'swim relax risk shy chimney please usual search industry board music segment' } stages { - stage('Test') { + stage('Tests with race flag') { steps { script { dir(env.REPO) { nix.develop('make test-with-race', pure: false) } } } } stage('Ganache') { + environment { + GANACHE_MNEMONIC = 'swim relax risk shy chimney please usual search industry board music segment' + } steps { script { ganache = docker.image( 'trufflesuite/ganache:v7.4.1' @@ -49,7 +51,7 @@ pipeline { } } } - stage('On-chain tests') { + stage('On-chain tests with race flag') { environment { GANACHE_NETWORK_RPC_URL = "ws://localhost:${env.GANACHE_RPC_PORT}" } From 95fc8ff77b0d7e499b061e49a19e666b62611ad6 Mon Sep 17 00:00:00 2001 From: Prem Chaitanya Prathi Date: Wed, 9 Aug 2023 10:21:20 +0530 Subject: [PATCH 11/11] chore:address review comments --- ci/Jenkinsfile.tests | 12 +++++- ci/Jenkinsfile.testsWithRace | 76 ------------------------------------ 2 files changed, 10 insertions(+), 78 deletions(-) delete mode 100644 ci/Jenkinsfile.testsWithRace diff --git a/ci/Jenkinsfile.tests b/ci/Jenkinsfile.tests index 4cf4b82c..1e528f5c 100644 --- a/ci/Jenkinsfile.tests +++ b/ci/Jenkinsfile.tests @@ -40,7 +40,11 @@ pipeline { stage('Test') { steps { script { dir(env.REPO) { - nix.develop('make test-ci', pure: false) + if (env.JOB_BASE_NAME == "race") { + nix.develop('make test-with-race', pure: false) + }else { + nix.develop('make test-ci', pure: false) + } } } } } @@ -60,7 +64,11 @@ pipeline { GANACHE_NETWORK_RPC_URL = "ws://localhost:${env.GANACHE_RPC_PORT}" } steps { script { dir(env.REPO) { - nix.develop('make test-onchain', pure: false) + if (env.JOB_BASE_NAME == "race") { + nix.develop('make test-onchain-with-race', pure: false) + }else { + nix.develop('make test-onchain', pure: false) + } } } } } } diff --git a/ci/Jenkinsfile.testsWithRace b/ci/Jenkinsfile.testsWithRace deleted file mode 100644 index d16e4603..00000000 --- a/ci/Jenkinsfile.testsWithRace +++ /dev/null @@ -1,76 +0,0 @@ -library 'status-jenkins-lib@v1.7.0' - -pipeline { - agent { - label 'linux && nix-2.11 && x86_64' - } - - options { - timestamps() - disableConcurrentBuilds() - /* Prevent Jenkins jobs from running forever */ - timeout(time: 30, unit: 'MINUTES') - /* Go requires a certain directory structure */ - checkoutToSubdirectory('src/github.com/waku-org/go-waku') - buildDiscarder(logRotator( - numToKeepStr: '10', - daysToKeepStr: '30', - )) - } - - environment { - TARGET = 'tests-with-race' - REPO = "${env.WORKSPACE}/src/github.com/waku-org/go-waku" - GOCACHE = "${env.WORKSPACE_TMP}/go-build" - GOPATH = "${env.WORKSPACE}/go" - PATH = "${env.PATH}:${env.GOPATH}/bin" - /* Necesary to avoid cache poisoning by other builds. */ - GOLANGCI_LINT_CACHE = "${env.WORKSPACE_TMP}/golangci-lint" - /* Ganache config */ - GANACHE_RPC_PORT = "${8989 + env.EXECUTOR_NUMBER.toInteger()}" - } - - stages { - stage('Tests with race flag') { - steps { script { dir(env.REPO) { - nix.develop('make test-with-race', pure: false) - } } } - } - - stage('Ganache') { - environment { - GANACHE_MNEMONIC = 'swim relax risk shy chimney please usual search industry board music segment' - } - steps { script { - ganache = docker.image( - 'trufflesuite/ganache:v7.4.1' - ).run( - "-p 127.0.0.1:${env.GANACHE_RPC_PORT}:8545", - "-m='${GANACHE_MNEMONIC}'" - ) - } } - } - - stage('On-chain tests with race flag') { - environment { - GANACHE_NETWORK_RPC_URL = "ws://localhost:${env.GANACHE_RPC_PORT}" - } - steps { script { dir(env.REPO) { - nix.develop('make test-onchain-with-race', pure: false) - } } } - } - } - post { - always { script { /* No artifact but a PKG_URL is necessary. */ - env.PKG_URL = "${currentBuild.absoluteUrl}consoleText" - } } - success { script { github.notifyPR(true) } } - failure { script { github.notifyPR(false) } } - cleanup { script { - cleanWs() - catchError { - ganache.stop() - } - } } - } -}