vapor / postgres-nio

🐘 Non-blocking, event-driven Swift client for PostgreSQL.
https://api.vapor.codes/postgresnio/documentation/postgresnio/
MIT License
322 stars 75 forks source link

Successfully closing connection logs `PSQLError` #411

Open slashmo opened 1 year ago

slashmo commented 1 year ago

Describe the bug

When successfully closing a connection, PostgresNIO includes a misleading "error" in its log statement.

To Reproduce

Steps to reproduce the behavior:

  1. Set a breakpoint in PostgresChannelHandler: https://github.com/vapor/postgres-nio/blob/1.18.1/Sources/PostgresNIO/New/PostgresChannelHandler.swift#L566
  2. Set log level to .trace or .debug
  3. Successfully establish a connection
  4. Close connection using connection.close()
  5. Using LLDB, inspect cleanup.error
  6. Find the log statement: psql_connection_id=0 psql_error=PSQLError – Generic description to prevent accidental leakage of sensitive data. For debugging details, use String(reflecting: error). [PostgresNIO] Cleaning up and closing connection.

Expected behavior

I would expect not to see an error in the log statement when the connection was closed successfully.

Environment

Additional context

I can see that closeConnectionAndCleanup already treats the error code clientConnectionClosed a special since it doesn't fire an error for it: https://github.com/vapor/postgres-nio/blob/abca6b390235ae337999d367c40cc40c99629385/Sources/PostgresNIO/New/PostgresChannelHandler.swift#L579 Perhaps the log statement could also conditionally exclude the error metadata if the code is clientConnectionClosed?