-
Notifications
You must be signed in to change notification settings - Fork 273
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
panic: unable to type check #416
Comments
Hi @martin-sucha, thanks for filling the issue. To alleviate the problem, we could:
Personally, I prefer options 2 and 3. The last one been iso-functional with the previous version of the rule. |
Okay, so I've seen another instance of the panic, indeed seems to be related to network since an unrelated job failed at the same time that clearly shown network error. Could you please confirm whether the type check actually downloads data from network or not? If it doesn't I need to check whether we have a bug in other parts of the CI job (which should have reported it instead). If it does, I'd like to pinpoint why the error message does not state that - I see the As for the changes here, we could do option 3, but since we need the type information to skip empty block for channel draining, missing package could cause the rule to emit wrong message (empty block) instead of the real one (missing package), which would be even harder to debug - so I would prefer an option that reports the type check failure. If we could provide more information about why a package could not be found in the error, even better. I've noticed that other call sites of |
I'd be surprised if the type checker uses network resources, this would introduce large latency. I'm thinking if the completeness we get with type checking is worth it the performance penalty. Maybe instead of solving #386, we can just reduce the confidence level. @chavacava @martin-sucha what do you think? |
@mgechev, I was thinking on something like that If type-checking is not OK we can go on but reducing the confidence level of failures at |
@martin-sucha wrote
It is a coherence problem we need to address |
Some more information from the investigation:
I've done 3rd step with and without network connection by applying After ~10 (this number changes randomly) successful runs, I got the similar panic mentioned by @martin-sucha. Packages in the panic messages were different (publicly available from github and private from our internal VCS). Also, I tried to reproduce a similar flow with Dockerfile where I tried to reproduce the errorFROM golang:1.14.2@sha256:09b04534495af5148e4cc67c8ac55408307c2d7b9e6ce70f6e05f7f02e427f68
ADD https://github.com/mgechev/revive/archive/3119f5881c5dd864f346426752eb745d3eddb17d.tar.gz /tmp/revive.tar.gz
RUN mkdir -p /revive &&\
tar xf /tmp/revive.tar.gz -C /revive --strip 1 &&\
rm -f /tmp/revive.tar.gz
WORKDIR /revive
RUN GO111MODULE=off go get -u -v github.com/mgechev/revive |
@chavacava I'd suggest to revert the fix which introduced type checking and reduce the confidence level. Looks like there were fewer cases when folks had issues with channel draining compared to the regression. WDYT? |
@mgechev I'm OK with reverting and reduce confidence (to how much?) |
The first option seems more deterministic. Alternatively, we can also match the most common channel training AST pattern, and still reduce with |
I see you removed the type check, which will fix the issue with panic. However, the type checking might still be failing in the other rules as well, the error is just suppressed, so it would be good to find the root cause of this. I managed to reproduce the panic (on version of code before you removed it from the empty-block rule) with just revive repo and it seems to happen more often than on the private repo we encountered the issue on. To reproduce, just checkout https://github.com/kiwicom/revive/commits/ms/issue-416-repro branch, build revive with Ultimately, I think we should find out whether the |
Also, I found out that there is a code path in https://github.com/golang/go/blob/dfd613e0e4fd93ef945e9fbd6d42b79bcaf73905/src/go/build/build.go#L1017 that spawns |
@martin-sucha thanks for your analysis and the tooling. Trying to get more information about the error, I've modified the configuration of the type-checker to: config := &types.Config{
// By setting a no-op error reporter, the type checker does as much work as possible.
Error: func(err error) { panic(err.Error()) },
//WAS Error: func(error) {},
Importer: newImporter(p.fset),
} Then I've used your script to reproduce the problem but... it works, no more panics |
Well further investigations show that setting |
Hmm, the behavior you described above is caused by defer func() {
if r := recover(); r != nil {
err, _ = r.(error)
p = nil
return
}
}() in If I change it to: defer func() {
if r := recover(); r != nil {
if r2, ok := r.(error); ok {
err = r2
} else {
panic(r)
}
p = nil
return
}
}() then the panic is reported correctly. |
Based on git history, the recover was added there to fix #59 |
A good example on why it is never a good idea to recover from panics :) I continue trying to find the root of the problem. The importer we use in the checker configuration (from
I'll follow the recommendation of using |
Describe the bug
We've seen a transient panic in revive in our CI job (it did not occur when the job was retried).
revive/rule/empty-block.go
Line 23 in 1da965b
To Reproduce
I couldn't reproduce the issue - it worked when I retried the job. Could it have been caused by some network issue when getting the package from our internal git repo?
Expected behavior
Expected to see better error message describing why it couldn't find the import.
Desktop (please complete the following information):
The text was updated successfully, but these errors were encountered: