Repository navigation
MongoDB sessions: no resurrection on save, legacy purge, key escaping; CI - #16
Merged
Merged
Conversation
…; CI - save() now replaces with upsert: false, so a save racing destroy() (logout) can't bring the session back. When nothing matched it logs at debug level (it's expected after a logout). Trade-off: a session whose create() insert failed, or that the TTL removed, is no longer re-created by the next save. - setup() deletes documents left by the archived Perfect-Session-MongoDB: string token, string data, created/updated/idle, no expiresAt. This driver can't resume them and the TTL index never expires them. The purge isn't in clean(), so during a rolling deploy it doesn't keep deleting sessions that old instances are still writing. README (en + zh_CN) has a migration note. - Keys in session.data are escaped at every depth: "%" -> "%25", NUL -> "%00", "" -> "%". libmongoc rejects an empty key, which failed the whole write (only logged), and a key was cut short at NUL. Other keys are stored unchanged, so data.<key> queries still work. Data written by main's driver with "%" in a key would be read back differently, but no tagged release contains the MongoDB driver yet. - Perfect-MongoDB floor raised to 4.0.2. - GitHub Actions CI. Linux (swift:6.4-resolute) runs every backend: SQLite through libsqlite3-dev, now that Perfect-SQLite builds on Linux (PerfectlySoft/Perfect-SQLite#23), plus real MongoDB, PostgreSQL, MySQL and Redis services. macOS builds and runs the core and SQLite tests. README (en + zh_CN) no longer calls the SQLite backend macOS-only. - The SQLite, PostgreSQL, MySQL and Redis suites are now serialized: each test sets the connector's global settings. The review saw the SQLite suite fail or segfault intermittently on main; 12 release runs here passed. The three new server tests (empty key, save after destroy, legacy purge) fail on main and pass here against MongoDB 8.3. The full suite passes in macOS debug and release, and on Linux (Swift 6.4, Ubuntu 26.04 container) with SQLite and against MongoDB 8, PostgreSQL 17, MySQL 8.4 and Redis 7. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Follow-ups to #14 from the adversarial review, plus the repo's first CI.
MongoDB backend
Logout can't be undone by a racing save.
save()now usesreplaceOne(upsert: false). When nothing matched, it logs at debug level, since this is expected after a logout. Trade-off: a session whosecreate()insert failed, or that the TTL index already removed, is no longer re-created by the next save.Legacy documents.
setup()deletes documents left by the archived Perfect-Session-MongoDB: stringtoken, stringdata,created/updated/idlepresent, and noexpiresAt. This driver can't resume them, and the TTL index never expires them. The purge isn't inclean(), so during a rolling deploy it won't keep deleting sessions that old instances are still writing. Unrelated documents with atokenfield are left alone (tested). The README has a migration section (en + zh_CN).Keys libmongoc won't store. Probed against MongoDB 8.3:
$xanda.bare fine.Keys in
dataare now escaped at every depth:%becomes%25, NUL becomes%00, and""becomes%. Other keys are stored unchanged, sodata.<key>queries still work. Data that main's driver already stored with%in a key would read back differently, but no tagged release contains the MongoDB driver yet.Perfect-MongoDB floor raised to
from: "4.0.2".CI and tests
.github/workflows/ci.yml:swift:6.4-resolute): every backend. SQLite runs throughlibsqlite3-dev, now that Build on Linux: add PerfectCSQLite system-library target Perfect-SQLite#23 builds on Linux. MongoDB, PostgreSQL, MySQL and Redis run against service containers.macos-26): build plus the core and SQLite tests (no servers). It setsPKG_CONFIG_PATHfor keg-onlylibpq/mysql-client..serialized, because each test sets the connector's global settings. The review saw the SQLite suite fail or segfault intermittently on main. Separately, 2 of 6 SQLite tests failed in parallel on Linux; with.serialized, 12 release runs on macOS passed.Verified
-c release -Xswiftc -enable-testing), with MongoDB and SQLite.macos-26runner's default Xcode.🤖 Generated with Claude Code