-
Notifications
You must be signed in to change notification settings - Fork 113
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
check/importShadow: panic due to concurrent access of PkgObjects
map
#1414
Comments
Hm, that's kinda interesting. @quasilyte do we share context between checks? |
@zakcutner can you share the full stacktrace for this data race please? |
PkgObjects
mapPkgObjects
map
@cristaloleg Unfortunately, I don't think I can share the stack trace dump of all goroutines, since this is from a private project, but here is the trace from the goroutine where the panic occurred:
I've also just found another concurrent map access panic that looks quite similar in the
Just in case it's relevant, I'm using nogo to run go-critic. |
This looks like a gocritic integration issue to me. |
@quasilyte Thanks for taking a look at this!
If I'm understanding correctly, the maps in the panics above are internal to go-critic? How should apps be synchronising reads/writes to these maps? If you might have some pointers or example code for what integrations should be doing, I'd be happy to take a look at the nogo integration to see if this is the issue. |
The linters need to be executed after the information is committed to the context. Tbh, go-critic was created before In my opinion, it would be bad to add synchronization to every read operation inside linters. |
@cristaloleg there are 2 contexts: shared and per-checker contexts. The basic execution loop looks like this (pseudo code!):
The parallelism can happen at both load and run phases, but they should not cross each other. |
Thanks for the helpful explanations, I think I understand this better now. I'm using the If I'm understanding correctly, I think the |
Yes, that's because every instantiated checker is expected to be run on a dedicated goroutine. It's a way for us to have a state that doesn't need sync and doesn't need to be shared. I really don't like the idea of protecting every state possible with a sync mechanism. We have multiple layers to avoid redundant sync. It's a pity that go/analysis makes it very awkward (with that being said, Originally, the parallelism model for gocritic looked like this: run every checker in a dedicated goroutine. So N checkers would result in N goroutines. |
Ah, I see! So the |
In my opinion, it would be easier for you to check out the way golangci-lint does it. Although I personally don't like the fact that it creates checkers per every package but I guess that's the only way to make it work with |
Makes sense! Would you be opposed to a PR to the |
It depends on whether it can be objectively seen as an improvement. |
Okay, I think that might be easiest to discuss with some code鈥擨'll open a draft PR to suggest some potential improvements. |
Thanks for all the advice! I've opened pull request #1416 to discuss this further, let me know your thoughts. |
Thanks for maintaining these very useful linters 馃槃
I've come across a
concurrent map iteration and map write
panic atcheckers/importShadow_checker.go#L34
. I'm using the latest version of go-critic (v0.11.3). I think that thePkgObjects
map is not protected against concurrent accesses.Unfortunately, I cannot find where the map is also written to concurrently, but should it be protected by a mutex? If this is the case, I'd be happy to contribute a fix.
The text was updated successfully, but these errors were encountered: