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

Fixed panic with dHelper. #4562

Merged
merged 1 commit into from Nov 16, 2023
Merged

Fixed panic with dHelper. #4562

merged 1 commit into from Nov 16, 2023

Conversation

Frozen
Copy link
Contributor

@Frozen Frozen commented Nov 14, 2023

panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x1a973f5]
goroutine 5441 [running]:
github.com/harmony-one/harmony/consensus.(*Consensus).spinUpStateSync(0xc00017a1e0)
/home/sp/harmony/harmony/consensus/downloader.go:107 +0x35
github.com/harmony-one/harmony/consensus.(*Consensus).onCommitted(0xc00017a1e0, 0xc008e3cfc0)

@Frozen Frozen self-assigned this Nov 14, 2023
@GheisMohammadi
Copy link
Contributor

it would be good if you can explain the issue and how this PR fixes it

@@ -19,12 +19,13 @@ type downloader interface {
// Set downloader set the downloader of the shard to consensus
// TODO: It will be better to move this to consensus.New and register consensus as a service
func (consensus *Consensus) SetDownloader(d downloader) {
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
consensus.dHelper = newDownloadHelper(consensus, d)
Copy link
Contributor Author

@Frozen Frozen Nov 15, 2023

Choose a reason for hiding this comment

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

This is where we initialize dHelper

@@ -104,7 +101,7 @@ func (consensus *Consensus) AddConsensusLastMile() error {
}

func (consensus *Consensus) spinUpStateSync() {
consensus.dHelper.d.DownloadAsync()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Here we use dHelper

@Frozen Frozen changed the title Fixed panic with dsync. Fixed panic with dHelper. Nov 15, 2023
@Frozen
Copy link
Contributor Author

Frozen commented Nov 15, 2023

Use of dHelper can happen before it initialization.
New version initializes dHelper in constructor with default value in order to avoid panic.
Other changes are fixes for a small bugs, i've found while debugging.

Comment on lines +280 to +281
consensus.mutex.Lock()
defer consensus.mutex.Unlock()
Copy link
Contributor

Choose a reason for hiding this comment

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

could you explain why we need this here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

this code is called from function BlockCommitSigs which is running in different goroutine. Without this lock it's going to be a race condition, because FBFTLog, which is called later, is not thread safe.

@sophoah
Copy link
Contributor

sophoah commented Nov 16, 2023

Use of dHelper can happen before it initialization.
New version initializes dHelper in constructor with default value in order to avoid panic.
Other changes are fixes for a small bugs, i've found while debugging.

Could you explain how at this issue happen. You have a fix here which is great, but i don't get how this issue happens at the first place

@Frozen
Copy link
Contributor Author

Frozen commented Nov 16, 2023

Use of dHelper can happen before it initialization.
New version initializes dHelper in constructor with default value in order to avoid panic.
Other changes are fixes for a small bugs, i've found while debugging.

Could you explain how at this issue happen. You have a fix here which is great, but i don't get how this issue happens at the first place

We had checks like if dSync != nil previously, so it didn't fail. Value is initialized with nil in constructor, later it's called or reinitialized, depending what happens faster

@Frozen Frozen merged commit 582a4cf into dev Nov 16, 2023
4 checks passed
@Frozen Frozen deleted the fix/panics-with-empty-dsync branch November 16, 2023 22:40
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.

None yet

4 participants