Skip to content

[pkg] Trace rw mutex#4578

Closed
envestcc wants to merge 1 commit intoiotexproject:masterfrom
envestcc:mutex
Closed

[pkg] Trace rw mutex#4578
envestcc wants to merge 1 commit intoiotexproject:masterfrom
envestcc:mutex

Conversation

@envestcc
Copy link
Member

Description

Introduce common module for easy debugging data race issues

Type of change

Please delete options that are not relevant.

  • [] Bug fix (non-breaking change which fixes an issue)
  • [] New feature (non-breaking change which adds functionality)
  • [] Code refactor or improvement
  • [] Breaking change (fix or feature that would cause a new or changed behavior of existing functionality)
  • [] This change requires a documentation update

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 marked this pull request as ready for review March 11, 2025 09:42
@sonarqubecloud
Copy link

@envestcc envestcc requested a review from Copilot March 11, 2025 12:53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR introduces a common module for debugging data race issues by wrapping the standard RWMutex with logging functionality.

  • Added a new RWMutex implementation with logging support
  • Provided an option to use a custom logger
  • Included a basic test file for verifying the mutex functionality

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/sync/rwmutex.go Implements the RWMutex wrapper with logging of lock/unlock events
pkg/sync/rwmutex_test.go Adds tests for basic sequential operations of the RWMutex
Comments suppressed due to low confidence (1)

pkg/sync/rwmutex_test.go:9

  • The tests currently only cover sequential locking and unlocking. Adding tests for concurrent access would help validate the thread-safety of RWMutex.
func TestRWMutex(t *testing.T) {

// NewRWMutex creates a new RWMutex with the provided options.
func NewRWMutex(opts ...RWMutexOption) *RWMutex {
rw := &RWMutex{
uuid: time.Now().Unix(),
Copy link

Copilot AI Mar 11, 2025

Choose a reason for hiding this comment

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

Using time.Now().Unix() for uuid may lead to collisions if multiple mutex instances are created within the same second. Consider using time.Now().UnixNano() for higher resolution.

Suggested change
uuid: time.Now().Unix(),
uuid: time.Now().UnixNano(),

Copilot uses AI. Check for mistakes.
}

func (lm *RWMutex) logger() *zap.Logger {
return lm.loggerFn().WithOptions(zap.AddCaller(), zap.AddCallerSkip(1)).With(zap.Int64("uuid", lm.uuid))
Copy link
Collaborator

Choose a reason for hiding this comment

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

could we keep the instance of lm.loggerFn()?

@envestcc envestcc closed this Apr 21, 2025
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.

3 participants