Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
server: avoid fragile pattern in NewServer
This pattern is bad: ```go func NewServer() *Server { s.a = newA() s.b = newB(s.a, s.c) s.c = newC() return s } ``` Note how `newB` gets called with `s.c == nil`. Creating a partially populated `Server` struc early is not a good idea; there is no protection against using fields before they are populated. Instead, use this pattern: ```go func NewServer() *Server { a := newA() c := newC() b := newB(a, c) return &Server{a: a, b: b, c: c} } ``` Note how the bug from the first example would be caught at compile time because we can't use something before it's defined. In fact, carrying out this refactor revealed a bug: we were always passing a `nil` engines slice to `NewNodeLiveness`, in effect disabling the disk stall protection in cockroachdb#32978. Release note: None
- Loading branch information