@@ -269,21 +269,30 @@ func (c *PostgresConnector) replicationOptions(publicationName string, pgVersion
269269
270270// Close closes all connections.
271271func (c * PostgresConnector ) Close () error {
272- var connerr , replerr error
272+ var errs [] error
273273 if c != nil {
274274 timeout , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
275275 defer cancel ()
276- connerr = c .conn .Close (timeout )
276+ if err := c .conn .Close (timeout ); err != nil {
277+ c .logger .Error ("failed to close Postgres connection" , slog .Any ("error" , err ))
278+ errs = append (errs , fmt .Errorf ("failed to close Postgres connection: %w" , err ))
279+ }
277280
278281 if c .replConn != nil {
279282 timeout , cancel := context .WithTimeout (context .Background (), 30 * time .Second )
280283 defer cancel ()
281- replerr = c .replConn .Close (timeout )
284+ if err := c .replConn .Close (timeout ); err != nil {
285+ c .logger .Error ("failed to close Postgres replication connection" , slog .Any ("error" , err ))
286+ errs = append (errs , fmt .Errorf ("failed to close Postgres replication connection: %w" , err ))
287+ }
282288 }
283289
284- c .ssh .Close ()
290+ if err := c .ssh .Close (); err != nil {
291+ c .logger .Error ("[postgres] failed to close SSH tunnel" , slog .Any ("error" , err ))
292+ errs = append (errs , fmt .Errorf ("[postgres] failed to close SSH tunnel: %w" , err ))
293+ }
285294 }
286- return errors .Join (connerr , replerr )
295+ return errors .Join (errs ... )
287296}
288297
289298func (c * PostgresConnector ) Conn () * pgx.Conn {
0 commit comments