Code Monkey home page Code Monkey logo

Comments (2)

vmihailenco avatar vmihailenco commented on July 22, 2024

Hey,

I assume that you use recover to continue execution, correct?

One possible issue with defer db.freeConn(cn, err) is that on panic it will put connection back to the pool, which can cause some side effects if data was not fully written/read.

An alternative would be to fix go-pg to never panic :) Can you please attach a backtrace showing the panic? Thanks.

from pg.

deni64k avatar deni64k commented on July 22, 2024

Yes, we use gin.Recover for that. Every panic is caught by that and the web application continues working.

In what cases could data be not fully written or read?

This is our backtrace:

ERROR: reflect: call of reflect.Value.Type on zero Value
goroutine 2973 [running]:
runtime/debug.Stack(0x0, 0x0, 0x0)
        /usr/local/Cellar/go/1.6/libexec/src/runtime/debug/stack.go:24 +0x80
github.com/housinganywhere/ha/vendor/github.com/housinganywhere/gomvc.GetHandler.func1.1(0x7fd60d47b458, 0xc821757b80)
        /Users/negval/Code/go/src/github.com/housinganywhere/ha/vendor/github.com/housinganywhere/gomvc/gomvc.go:103 +0x284
panic(0xf09200, 0xc821ed9260)
        /usr/local/Cellar/go/1.6/libexec/src/runtime/panic.go:426 +0x4e9
reflect.Value.Type(0x0, 0x0, 0x0, 0x0, 0x0)
        /usr/local/Cellar/go/1.6/libexec/src/reflect/value.go:1671 +0x7b
github.com/housinganywhere/pg.NewColumnLoader(0xfd2120, 0x0, 0x0, 0x0, 0x0, 0x0)
        /Users/negval/Code/go/src/github.com/housinganywhere/pg/loader.go:176 +0x2a8
github.com/housinganywhere/pg.readDataRow(0xc8222974a0, 0xfd2120, 0x0, 0xc822722ae0, 0x6, 0x6, 0x0, 0x0)
        /Users/negval/Code/go/src/github.com/housinganywhere/pg/messages.go:407 +0xe0
github.com/housinganywhere/pg.readSimpleQueryData(0xc8222974a0, 0x7fd60d275860, 0xc8220165b0, 0x0, 0x0, 0x0)
        /Users/negval/Code/go/src/github.com/housinganywhere/pg/messages.go:454 +0x1ee
github.com/housinganywhere/pg.simpleQueryData(0xc8222974a0, 0x7fd60d275860, 0xc8220165b0, 0xc821af9c80, 0x3d, 0xc822516388, 0x2, 0x2, 0x0, 0x0, ...)
        /Users/negval/Code/go/src/github.com/housinganywhere/pg/db.go:413 +0x122
github.com/housinganywhere/pg.(*DB).Query(0xc8201af0f0, 0x7fd60d275860, 0xc8220165b0, 0xc821af9c80, 0x3d, 0xc822516388, 0x2, 0x2, 0x0, 0x0, ...)
        /Users/negval/Code/go/src/github.com/housinganywhere/pg/db.go:233 +0xee
github.com/housinganywhere/pg.(*DB).QueryOne(0xc8201af0f0, 0xfd2120, 0x0, 0xc821af9c80, 0x3d, 0xc822516388, 0x2, 0x2, 0x199, 0x0, ...)
        /Users/negval/Code/go/src/github.com/housinganywhere/pg/db.go:246 +0xec
github.com/housinganywhere/repo-pg.SelectOne(0xfd2120, 0x0, 0xc821af9c80, 0x3d, 0xc822516388, 0x2, 0x2, 0x0, 0x0)
        /Users/negval/Code/go/src/github.com/housinganywhere/repo-pg/repo.go:117 +0x620
...cut...

I'd suggest this quick fix:

        func() {
            defer db.freeConn(cn, err)
            res, err = simpleQuery(cn, q, args...)
        }()

Since defer calls are executed after function returns, it is better to narrow its scope and put a connection back straight away after using, not when DB.Query returns.

from pg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.