Skip to content

Conversation

@IDisposable
Copy link
Contributor

This update enhances the performance and features of the synctrace logging of Lock/Unlock/TryLock for Mutex and RWMutex for improved visibility into concurrent operations and aids in debugging synchronization-related issues by providing more detailed synctrace logging.

sync changes

  • Switched the maps to be indexed by the .Pointer as a uintptr (not as a string) so map is smaller and faster.
  • Grouped the lockCount, unlockCount, and lastLock into a trackingEntry so we can detect unlocks of something that wasn't ever locked, excessive unlocks, and also track the firstLock and the lastUnlock.
  • Added LogDangledLocks for debugging use, just insert a call to this anywhere you might have concerns.
  • Added a panic handler to the Main so we can log out panics

other changes

Migrates from standard library sync package imports to an internal internal/sync package across almost all of the codebase.

Exceptions:

  • jsonrpc.go Way too busy*
  • usb.go Way too busy*
  • dc_metrics.go Only uses a sync.Once which isn't worth tracking
  • internal/logging/logger.go Logging logs while logging messages seems too loggish
  • internal/native/cgo_linux.go Very performance intensive and too busy when tracing*
  • internal/sync/log.go Wouldn't be worthwhile logging lock usage inside the sync logging itself
  • pkg/myip/check.go Stand-alone package that only uses the trackables in checkIP function to sync its own children
  • pkg/myip/ip.go Stand-alone package

* These are performance sensitive or very frequent lock/unlock that just emits too many logs to track. If there's a problem in those modules, you can temporarily swap over to using the logger by replacing import "sync" with import "github.com/jetkvm/kvm/internal/sync"

Switched the maps to be indexed by the .Pointer (not a string)
Grouped the lockCount, unlockCount ,and lastLock in an trackingEntry so we can detect unlocks of something that wasn't ever locked and excessive unlocks and also tracks the first time locked and the last unlock time.
Added LogDangledLocks for debugging use.
Added a panic handler to the Main so we can log out panics
Copy link
Contributor

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 enhances the synctrace logging functionality for Mutex and RWMutex operations to improve debugging of concurrent operations. The implementation switches from string-based indexing to pointer-based indexing for better performance and adds detection of lock/unlock imbalances.

Key changes:

  • Refactored tracking maps to use uintptr keys instead of string keys for improved performance
  • Added comprehensive tracking with trackingEntry struct including first lock, last lock, and last unlock times
  • Implemented LogDangledLocks() function to detect held locks and excessive unlocks

Reviewed Changes

Copilot reviewed 21 out of 21 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
internal/sync/log.go Core refactoring: switched to uintptr-based tracking, added trackingEntry struct, implemented LogDangledLocks and unlock validation
internal/sync/release.go Added no-op LogDangledLocks for non-synctrace builds
main.go Added panic recovery handler with logging
webrtc.go, web_tls.go, usb_mass_storage.go, native.go, etc. Migrated from stdlib sync to internal/sync package
DEVELOPMENT.md Added documentation for synctrace debugging and troubleshooting

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

IDisposable and others added 2 commits November 18, 2025 19:19
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.

1 participant