Close bad connection to solve CLOSE_WAIT stuck#722
Conversation
d6b8906 to
d6e1f31
Compare
|
https://golang.org/src/database/sql/sql.go#L1045 only close errBadConn. If lib/pq doesn't close connection when set conn.bad flag, the close of the bad connection will not be called. |
I would like to ask if the repair of this code works normally and can reduce the establishment of close_wait stuck? |
|
This pr I worked with was at golang 10, you can find golang source code I referred here https://github.com/golang/go/blob/release-branch.go1.10/src/database/sql/sql.go#L1045. |
Thank you your reply.... This means that if my go version is 1.9, I need to modify it in the way of your previous pr (d6b8906) to avoid the close_wait problem? |
|
https://github.com/golang/go/blob/release-branch.go1.9/src/database/sql/sql.go#L946 |
d6e1f31 to
f51b554
Compare
|
My ci still fails because of race condition but it's not related to this pr .... |
|
It seems conn.Close() is always called on ErrBadConn by database/sql? I tried to replicate this with the pqtest.Fake server, but I can't really reproduce it: conn.Close() is always called. The logic in conn.Close() where it tries to send a Terminate message to the server is probably better than outright closing the connection? Since this is a few years old I'll just go ahead and close it, but let me know if I'm mistaken and we can re-open. |
Somehow server side would close connection actively (timeout, server close, etc...). Therefore, client should ack close in this situation, otherwise client process will be fulled of CLOSE_WAIT and stuck finally.