bradleyfalzon / closecheck Goto Github PK
View Code? Open in Web Editor NEWCheck for missing close method calls on objects that may require them - SEE EPILOGUE
License: Apache License 2.0
Check for missing close method calls on objects that may require them - SEE EPILOGUE
License: Apache License 2.0
Library authors that have a constructor, such as func New() *T
which also has a func (*T) Close() error
will have an error reported in the constructor.
This maybe fixed with some special case handling by checking if the type has a locally defined Close()
method (somehow).
Support ./...
in one way or another.
Caddy has an edge case where it's complaining something isn't closed, but technically it eventually is, and closecheck should handle this. This maybe too complex to handle, but ideally, closecheck should decide that it couldn't tell, so it shouldn't error.
I need to investigate why (probably as it's wrapped in a struct+map.
151 restartFds := make(map[string]restartPair)
152 for _, s := range i.servers {
153 gs, srvOk := s.server.(GracefulServer)
154 ln, lnOk := s.listener.(Listener)
155 if srvOk && lnOk {
156 restartFds[gs.Address()] = restartPair{server: gs, listener: ln}
157 }
158 }
...
163 // attempt to start new instance
164 err := startWithListenerFds(newCaddyfile, newInst, restartFds)
165 if err != nil {
166 return i, err
167 }
Eventually it is closed:
547 if gs, ok := s.(GracefulServer); ok && restartFds != nil {
548 addr := gs.Address()
549 if old, ok := restartFds[addr]; ok {
550 file, err := old.listener.File()
551 if err != nil {
552 return err
553 }
554 ln, err = net.FileListener(file)
555 if err != nil {
556 return err
557 }
558 file.Close()
559 }
560 }
panic: interface conversion: ast.Expr is *ast.SelectorExpr, not *ast.Ident
goroutine 1 [running]:
panic(0x65fba0, 0xc42caba7c0)
/usr/local/go/src/runtime/panic.go:500 +0x1a1
github.com/bradleyfalzon/closecheck.(*visitor).Visit(0xc42cab5890, 0x7f3b4da89d28, 0xc420ce8990, 0x1, 0xc4212334a0)
/home/bradleyf/go/src/github.com/bradleyfalzon/closecheck/closecheck.go:235 +0x674
go/ast.Walk(0x7b7400, 0xc42cab5890, 0x7f3b4da89d28, 0xc420ce8990)
/usr/local/go/src/go/ast/walk.go:52 +0x63
go/ast.walkStmtList(0x7b7400, 0xc42cab5890, 0xc420944420, 0x2, 0x2)
/usr/local/go/src/go/ast/walk.go:32 +0x89
go/ast.Walk(0x7b7400, 0xc42cab5890, 0x7b7e80, 0xc420f1c1e0)
/usr/local/go/src/go/ast/walk.go:224 +0x1d48
go/ast.Walk(0x7b7400, 0xc42cab5890, 0x7b80c0, 0xc420ce8a40)
/usr/local/go/src/go/ast/walk.go:98 +0x2ffa
go/ast.Walk(0x7b7400, 0xc42cab5890, 0x7b7ec0, 0xc4207fc100)
/usr/local/go/src/go/ast/walk.go:136 +0x11f5
go/ast.Walk(0x7b7400, 0xc42cab5890, 0x7f3b4da89f68, 0xc420ce8a50)
/usr/local/go/src/go/ast/walk.go:213 +0x2054
go/ast.walkStmtList(0x7b7400, 0xc42cab5890, 0xc420285580, 0x8, 0x8)
/usr/local/go/src/go/ast/walk.go:32 +0x89
go/ast.Walk(0x7b7400, 0xc42cab5890, 0x7b7e80, 0xc420f1c840)
/usr/local/go/src/go/ast/walk.go:224 +0x1d48
go/ast.Walk(0x7b7400, 0xc42cab5890, 0x7f3b4ddac220, 0xc4207fc340)
/usr/local/go/src/go/ast/walk.go:231 +0x1f1a
go/ast.walkStmtList(0x7b7400, 0xc42cab5890, 0xc4219c6600, 0xc, 0x10)
/usr/local/go/src/go/ast/walk.go:32 +0x89
go/ast.Walk(0x7b7400, 0xc42cab5890, 0x7b7e80, 0xc420f1ca80)
/usr/local/go/src/go/ast/walk.go:224 +0x1d48
go/ast.Walk(0x7b7400, 0xc42cab5890, 0x7b8080, 0xc420f1cab0)
/usr/local/go/src/go/ast/walk.go:344 +0xf03
github.com/bradleyfalzon/closecheck.Check(0xc420675000, 0xc4202404d0, 0xc42aba1eb8, 0x0, 0x1)
/home/bradleyf/go/src/github.com/bradleyfalzon/closecheck/closecheck.go:37 +0x1a3
Code:
233 if interfaceCloses(iface) {
234 // Function's argument requires an io.Closer, it will likely close it
235 argIdent := fun.Args[i].(*ast.Ident)
236 if argIdent != nil {
237 v.addClosed(v.pi.ObjectOf(argIdent).Pos())
238 }
239 }
Offending line:
314 checkClose(resp.Body, &err)
argIdent
probably just needs to be swapped around for exprDef
function.
Possibly add special case handling for net/http.Response
, to ensure the .Body
is closed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.