vapor / postgres-nio

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

`close()` closes immediately; Add new `closeGracefully()` #383

Closed fabianfett closed 1 year ago

fabianfett commented 1 year ago

Fixes #370.

This PR changes the behavior of close(). close() now closes a connection immediately. We introduce a closeGracefully() that now has the same behavior as close before. Since we never documented the old close behavior and it is unfortunate that close does depend on the remote server to fulfill all queries, we consider it okay to change the behavior in this way. The current behavior is harmful since there is currently no way to force close a connection. Users might be in a position to force close a connection if a server stops responding.

Alternative: close keeps graceful close behavior and we add a closeForcefully method instead

codecov-commenter commented 1 year ago

Codecov Report

Merging #383 (ecdb6f5) into main (a5758b0) will increase coverage by 1.46%. The diff coverage is 71.31%.

Additional details and impacted files ```diff @@ Coverage Diff @@ ## main #383 +/- ## ========================================== + Coverage 46.07% 47.53% +1.46% ========================================== Files 109 109 Lines 8728 8764 +36 ========================================== + Hits 4021 4166 +145 + Misses 4707 4598 -109 ``` | [Files Changed](https://app.codecov.io/gh/vapor/postgres-nio/pull/383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor) | Coverage Δ | | |---|---|---| | [Sources/PostgresNIO/New/PSQLEventsHandler.swift](https://app.codecov.io/gh/vapor/postgres-nio/pull/383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9Qb3N0Z3Jlc05JTy9OZXcvUFNRTEV2ZW50c0hhbmRsZXIuc3dpZnQ=) | `72.41% <ø> (ø)` | | | [Sources/PostgresNIO/Postgres+PSQLCompat.swift](https://app.codecov.io/gh/vapor/postgres-nio/pull/383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9Qb3N0Z3Jlc05JTy9Qb3N0Z3JlcytQU1FMQ29tcGF0LnN3aWZ0) | `0.00% <0.00%> (ø)` | | | [Sources/PostgresNIO/New/PSQLError.swift](https://app.codecov.io/gh/vapor/postgres-nio/pull/383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9Qb3N0Z3Jlc05JTy9OZXcvUFNRTEVycm9yLnN3aWZ0) | `79.02% <66.66%> (+5.18%)` | :arrow_up: | | [...nection State Machine/ConnectionStateMachine.swift](https://app.codecov.io/gh/vapor/postgres-nio/pull/383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9Qb3N0Z3Jlc05JTy9OZXcvQ29ubmVjdGlvbiBTdGF0ZSBNYWNoaW5lL0Nvbm5lY3Rpb25TdGF0ZU1hY2hpbmUuc3dpZnQ=) | `58.59% <70.00%> (+2.90%)` | :arrow_up: | | [...es/PostgresNIO/Connection/PostgresConnection.swift](https://app.codecov.io/gh/vapor/postgres-nio/pull/383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9Qb3N0Z3Jlc05JTy9Db25uZWN0aW9uL1Bvc3RncmVzQ29ubmVjdGlvbi5zd2lmdA==) | `41.11% <85.71%> (+6.51%)` | :arrow_up: | | [.../Connection State Machine/ListenStateMachine.swift](https://app.codecov.io/gh/vapor/postgres-nio/pull/383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9Qb3N0Z3Jlc05JTy9OZXcvQ29ubmVjdGlvbiBTdGF0ZSBNYWNoaW5lL0xpc3RlblN0YXRlTWFjaGluZS5zd2lmdA==) | `69.03% <87.50%> (+0.57%)` | :arrow_up: | | [...urces/PostgresNIO/New/PostgresChannelHandler.swift](https://app.codecov.io/gh/vapor/postgres-nio/pull/383?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor#diff-U291cmNlcy9Qb3N0Z3Jlc05JTy9OZXcvUG9zdGdyZXNDaGFubmVsSGFuZGxlci5zd2lmdA==) | `78.21% <100.00%> (+5.94%)` | :arrow_up: | ... and [5 files with indirect coverage changes](https://app.codecov.io/gh/vapor/postgres-nio/pull/383/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=vapor)