NilAway: Practical Nil Panic Detection for Go
Summary
NilAway is Uber’s static analyzer for detecting potential nil pointer dereferences in Go before they reach production, where nil panics have caused incorrect behavior, outages, and denial-of-service risks. It models nilability flows as global typing constraints over struct fields, function parameters, and return values, builds an implication graph, and uses 2-SAT-style reasoning with forward nilness and backward nonnil propagation to identify contradictions. The analysis is interprocedural, requires no developer annotations, and reports detailed flows, while acknowledging false positives when runtime invariants are not captured. In one Uber service logging more than 3,000 nil panics daily, NilAway identified a receive-from-closed-channel path; adding a nilness check reduced the reported panics to zero, and the tool was released as open source with comprehensive and changed-code onboarding options.
Context
Uber’s 90-million-line Go monorepo had experienced production runtime errors from nil panics, including incorrect behavior and app outages. Existing nilness analysis detected only simple dereferences, while adapting Java’s annotation-based NullAway approach was impractical because Go lacks annotation support and annotating the monorepo would be cumbersome.
Approach / What changed
NilAway uses interprocedural static analysis and inference to model nilability as global typing constraints. It captures nilable and nonnil constraints for struct fields, parameters, and return values, builds an implication graph, and uses 2-SAT-style propagation to report unsafe nil flows. It supports comprehensive enforcement or non-blocking changed-code checks, without requiring annotations.
Takeaways
NilAway identifies contradictions where a witnessed nil value flows to a site requiring a nonnil value, then reports the detailed path from the nil source to the dereference.
The analysis can produce false positives when subtle interprocedural execution invariants prevent a nil flow at runtime, although the source reports a low false-positive rate in practice.
In a service logging more than 3,000 nil panics per day, NilAway found a receive-from-closed-channel path; adding a nilness check reduced the reported panics to zero.
Source and freshness
- Source
- uber.com
- Published
- Added to Yomu
Summaries are generated from the original by a language model. Check the original before relying on it.
Keep reading
Related reading
The Good Stuff
Paid picks we use ourselves. Links carry a referral code — a subscription through one earns us a commission at no extra cost to you.
The best engineering reads, once a week
One useful email. Unsubscribe anytime.