{"id":13771531,"url":"https://github.com/gnieto/mulint","last_synced_at":"2025-04-09T22:40:46.705Z","repository":{"id":97706445,"uuid":"121904246","full_name":"gnieto/mulint","owner":"gnieto","description":"Go lint which detects recursive locks, which may lead to dead locks","archived":false,"fork":false,"pushed_at":"2020-07-20T15:03:28.000Z","size":106,"stargazers_count":16,"open_issues_count":2,"forks_count":4,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-24T00:38:05.294Z","etag":null,"topics":["deadlock","go","golint","lint"],"latest_commit_sha":null,"homepage":null,"language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/gnieto.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-02-18T00:22:35.000Z","updated_at":"2024-11-19T10:07:31.000Z","dependencies_parsed_at":"2023-04-17T14:02:04.251Z","dependency_job_id":null,"html_url":"https://github.com/gnieto/mulint","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnieto%2Fmulint","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnieto%2Fmulint/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnieto%2Fmulint/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/gnieto%2Fmulint/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/gnieto","download_url":"https://codeload.github.com/gnieto/mulint/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248124843,"owners_count":21051757,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["deadlock","go","golint","lint"],"created_at":"2024-08-03T17:00:52.435Z","updated_at":"2025-04-09T22:40:46.672Z","avatar_url":"https://github.com/gnieto.png","language":"Go","funding_links":[],"categories":["Linters"],"sub_categories":["Bugs"],"readme":"# mulint\n\nmulint is a program/lint to check potential dead locks on go programs. The documentation for `sync.RWMutex` says:\n\n```\nIf a goroutine holds a RWMutex for reading and another goroutine might call Lock, no goroutine should expect to be able to acquire a read lock until the initial read lock is released. In particular, this prohibits recursive read locking. This is to ensure that the lock eventually becomes available; a blocked Lock call excludes new readers from acquiring the lock.\n```\n\nAs this is stated on the documentation, but is not enforced by the language nor the library, this program tries to detect some recursive read locks on the same goroutine.\n\n## Install\n\nAs usual on Go environment, to install, run the following command:\n\n```\ngo get -u github.com/gnieto/mulint\n```\n\nThis should install the lint on your `$GOPATH`.\n\n## Running\n\nTo run the lint, you just need to:\n\n```\nmulint ./...\n```\n\nNote that this lint uses `golang.org/x/tools`, so all the usual wildcards to filter or select packages should work.\n\nOn the following lines, you can see an example of output of this lint:\n\n```\nmixed_locks.go:27: Mutex lock is acquired on this line: m.Test()\n\tmixed_locks.go:24: But the same lock was acquired here: m.m.Lock()\n```\n\nThe first line indicates where the recursive lock is acquired (so, the second `Lock` on the same goroutine), the file and line where it occurs. The second one, indicate where the first `Lock` occurs\n\n## Exit code\n\nIf the program detects some error, it will return a 1 as error code\n\n## Limitations\n\nAt the moment, it can only detect some basic scenarios when a `Mutex` or `RWMutex` is part of a struct and all the `Lock` and `Unlock` operations are executed inside the scopes of the mentioned struct.\nSo, it may detect a recursive call like the following one:\n\n```go\ntype someStruct struct {\n  m sync.RWMutex\n}\n\nfunc (s *someStruct) A() {\n  s.m.RLock()\n  s.B()\n  s.m.RUnlock()\n}\n\nfunc (s *someStruct) B() {\n  s.m.RLock() // This is a recursive lock and it should be detected by this tool\n  s.m.RUnlock()\n}\n```\n\nBut it's not able to detect a recursive lock when a mutex is moved to another scope, as it may happen with `func`s\n\n```go\nvar m sync.RWMutex\n\nA(m)\n\nfunc A(m *sync.RWMutex) {\n  m.RLock()\n  B(m)\n  m.RUnlock()\n}\n\nfunc B(m *sync.RWMutex) {\n  m.RLock()\n  m.RUnlock()\n}\n```\n\nThere is no technical limitation (as far as I am aware) to track when a mutex is moved, but I left this cases for now. Feel free to do the change and open a PR to include this case.\n\nFinally, all the analysis is done per package. If there's some recursive `RLock` which operates among distinct packages, it won't be detected by this lint.\n\n## Attribution\n\n- I have checked the `errcheck` code (https://github.com/kisielk/errcheck) as an example of how the AST is walked on Go\n- Lint uses gosec (https://github.com/securego/gosec), just for a method that refused to re-writte myself (`GetCallInfo`)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnieto%2Fmulint","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fgnieto%2Fmulint","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fgnieto%2Fmulint/lists"}