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

[actsync] Fix data race #4456

Merged
merged 3 commits into from
Nov 28, 2024
Merged

[actsync] Fix data race #4456

merged 3 commits into from
Nov 28, 2024

Conversation

envestcc
Copy link
Member

Description

Fixes #4399

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • [] make test
  • [] fullsync
  • [] Other test (please specify)

Test Configuration:

  • Firmware version:
  • Hardware:
  • Toolchain:
  • SDK:

Checklist:

  • [] My code follows the style guidelines of this project
  • [] I have performed a self-review of my code
  • [] I have commented my code, particularly in hard-to-understand areas
  • [] I have made corresponding changes to the documentation
  • [] My changes generate no new warnings
  • [] I have added tests that prove my fix is effective or that my feature works
  • [] New and existing unit tests pass locally with my changes
  • [] Any dependent changes have been merged and published in downstream modules

@envestcc envestcc requested a review from a team as a code owner October 23, 2024 08:21
Copy link

sonarcloud bot commented Oct 23, 2024

@@ -95,7 +95,6 @@ func (as *ActionSync) Stop(ctx context.Context) error {
return err
}
close(as.quit)
close(as.syncChan)
Copy link
Member Author

Choose a reason for hiding this comment

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

do not close the channel, so it will not panic.

Copy link
Member

@dustinxie dustinxie Oct 31, 2024

Choose a reason for hiding this comment

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

better to close the channel, otherwise we are leaving a channel that may still have data (and possibly a memory leak)
can send to another chan in sync(), and wait that channel here, then close syncChan

<- as.exit
close(as.syncChan)

log.L().Warn("Failed to request action from neighbors", zap.Error(err))
counterMtc.WithLabelValues("failed").Inc()
}
case <-as.quit:
Copy link
Member Author

Choose a reason for hiding this comment

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

quit immediately may cause data discard, but it should be acceptable when stop service

Copy link
Member

@dustinxie dustinxie Oct 31, 2024

Choose a reason for hiding this comment

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

have another channel and close it here, so Stop() can receive from this channel, and continue close the service

as.exit <- struct{}{}
log.L().Info("quitting action sync")
return

@Liuhaai
Copy link
Member

Liuhaai commented Nov 26, 2024

add unit tests for the fix

Copy link

sonarcloud bot commented Nov 27, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
41.9% Duplication on New Code (required ≤ 3%)

See analysis details on SonarQube Cloud

@envestcc envestcc merged commit 5b64c2b into iotexproject:master Nov 28, 2024
2 of 3 checks passed
@envestcc envestcc deleted the bug-datarace branch November 28, 2024 00:45
dustinxie pushed a commit that referenced this pull request Dec 4, 2024
@dustinxie dustinxie mentioned this pull request Dec 6, 2024
6 tasks
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.

sporadic data race in actionsync test
3 participants