Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix_: wakuv2 waitgroups #5814

Merged
merged 2 commits into from
Sep 12, 2024
Merged

fix_: wakuv2 waitgroups #5814

merged 2 commits into from
Sep 12, 2024

Conversation

igor-sirotin
Copy link
Collaborator

Problem

In nightly tests, there was a panic:

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x20 pc=0x17747a8]

goroutine 1180314 [running]:
github.com/status-im/status-go/wakuv2.(*Waku).processQueueLoop(0xc04ff7eb40)
	/home/jenkins/workspace/status-go/tests-nightly/wakuv2/waku.go:1416 +0xc8
created by github.com/status-im/status-go/wakuv2.(*Waku).Start in goroutine 1179373
	/home/jenkins/workspace/status-go/tests-nightly/wakuv2/waku.go:1146 +0x8d6

That's because there's a loop and we might access a nil w.ctx when stopping waku.

status-go/wakuv2/waku.go

Lines 1421 to 1428 in daa3695

for {
select {
case <-w.ctx.Done():
return
case e := <-w.msgQueue:
w.processMessage(e)
}
}

Fixes

  1. I fixed the panic by adding a waitgroup to it.
  2. Refactored the way we add to waitgroups, which should be done outside the goroutine (my mistake actually).

@igor-sirotin igor-sirotin requested review from richard-ramos and a team September 9, 2024 15:51
@status-im-auto
Copy link
Member

status-im-auto commented Sep 9, 2024

Jenkins Builds

Commit #️⃣ Finished (UTC) Duration Platform Result
✔️ daa3695 #1 2024-09-09 15:54:02 ~2 min tests-rpc 📄log
✔️ daa3695 #1 2024-09-09 15:55:29 ~4 min linux 📦zip
✔️ daa3695 #1 2024-09-09 15:57:13 ~5 min android 📦aar
✔️ daa3695 #1 2024-09-09 16:24:35 ~33 min tests 📄log
✔️ daa3695 #2 2024-09-12 14:04:12 ~5 min ios 📦zip

@@ -1092,9 +1090,12 @@ func (w *Waku) Start() error {
}
}()

w.wg.Add(1)
Copy link
Contributor

@dlipicar dlipicar Sep 9, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we've got services/wallet/async/async.go Group for managing this repeating pattern of adding 1 to the WaitGroup and running a thingy in a goroutine. Kind of a small pattern, but it should prevent the kind of bug where you forget to add 1.
If the @status-im/status-go-guild likes it, we can extend usage of it.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh shit just realized that class goes directly against https://www.notion.so/Code-smell-2-Pass-context-to-functions-cd49904001ca4152be006124e64f5c61
🤔

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dlipicar Not sure about this. WaitGroup itself is a pretty simple class and straight-forward to use. And wrapping it into such things unnecessary complicates it IMO.

@igor-sirotin igor-sirotin merged commit 13ab5b6 into develop Sep 12, 2024
11 checks passed
@igor-sirotin igor-sirotin deleted the fix/wakuv2-waitgroups branch September 12, 2024 14:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants