Closed xin-tsla closed 1 year ago
Hi @elliotcourant , wondering when you have time, could you take a second look?
Thank you very much for the fix @xin-tsla !
@elliotcourant , happy to work on the fix! And much appreciate your review and time! :)
@elliotcourant , when you have time, another question, could you create a new release version?
I can tag it for release this week, gonna try to loop in some other changes with that release as well. Mostly dependency bumps.
@elliotcourant , got it. Thank you so much for tagging the release! :)
@elliotcourant , by chance when you have time, could you tag a new release version?
@xin-tsla Sorry for the delay! It is now tagged!
@elliotcourant , no worries! Thanks for tagging it! Much appreciate your time!
Hi All, The issue this PR tries to solve is that we observed an NPE in
OnConnect
method https://github.com/go-pg/pg/blob/f7e1c98fed3044ae4e195a0e063f69185fb1885b/base.go#L119 when we callconn.Exec()
twice inside theOnConnect
method. and the second call (conn.Exec()
) may get annil
conn object and fails to callconn.Exec()
[panic].The data flow diagram depicts how the conn is
nil
in some case:If
ctx
gets cancelled and returns before query finishes (Yellow line in the diagram), theconn
inSingleConnPool
will callRemove
method to set the conn tonil
: https://github.com/go-pg/pg/blob/f7e1c98fed3044ae4e195a0e063f69185fb1885b/internal/pool/pool_single.go#L38 and as well to set an error with reason, which isnil
since it is due toctx
gets cancelled without an error: https://github.com/go-pg/pg/blob/f7e1c98fed3044ae4e195a0e063f69185fb1885b/internal/pool/pool_single.go#L39When
ctx
is cancelled: https://github.com/go-pg/pg/blob/f7e1c98fed3044ae4e195a0e063f69185fb1885b/base.go#L153 and sendstruct{}{}
to fnDone: https://github.com/go-pg/pg/blob/f7e1c98fed3044ae4e195a0e063f69185fb1885b/base.go#L159