2
0

Conn.Close waits for server to close connection

This commit is contained in:
Jack Christensen
2017-03-05 13:47:28 -06:00
parent af8519991e
commit 071f4cc2ad
+27 -7
View File
@@ -425,20 +425,40 @@ func (c *Conn) Close() (err error) {
} }
} }
_, err = c.conn.Write([]byte{'X', 0, 0, 0, 4}) defer func() {
if err != nil && c.shouldLog(LogLevelWarn) { c.conn.Close()
c.log(LogLevelWarn, "Failed to send terminate message", "err", err)
}
err = c.conn.Close()
c.die(errors.New("Closed")) c.die(errors.New("Closed"))
if c.shouldLog(LogLevelInfo) { if c.shouldLog(LogLevelInfo) {
c.log(LogLevelInfo, "Closed connection") c.log(LogLevelInfo, "Closed connection")
} }
}()
err = c.conn.SetDeadline(time.Time{})
if err != nil && c.shouldLog(LogLevelWarn) {
c.log(LogLevelWarn, "Failed to clear deadlines to send close message", "err", err)
return err return err
} }
_, err = c.conn.Write([]byte{'X', 0, 0, 0, 4})
if err != nil && c.shouldLog(LogLevelWarn) {
c.log(LogLevelWarn, "Failed to send terminate message", "err", err)
return err
}
err = c.conn.SetReadDeadline(time.Now().Add(5 * time.Second))
if err != nil && c.shouldLog(LogLevelWarn) {
c.log(LogLevelWarn, "Failed to set read deadline to finish closing", "err", err)
return err
}
_, err = c.conn.Read(make([]byte, 1))
if err != io.EOF {
return err
}
return nil
}
// ParseURI parses a database URI into ConnConfig // ParseURI parses a database URI into ConnConfig
// //
// Query parameters not used by the connection process are parsed into ConnConfig.RuntimeParams. // Query parameters not used by the connection process are parsed into ConnConfig.RuntimeParams.