Repository navigation
fix(activesync): keep the Mongo state lock on the document it was taken on - #118
Merged
ralflang merged 1 commit intoNov 13, 2026
Conversation
…en on State_Mongo addressed its document lock through the current sync key and collection of the state object. Both change before the lock is released: setNewSyncKey() sets the key of the state to be saved, and loadState() sets the next key and collection. - Remember the sync key the lock was acquired on and release the lock by that key. The lock of the previously loaded folder is now released when the next folder is loaded. - A state saved under a new sync key is inserted as a new document and the lock on the loaded document is released afterwards. Before, the locked update looked for the not yet existing document and every such save failed with "Error saving state." - Look the FOLDERSYNC state up under the folder id save() stores it with, instead of the unset collection id. Tests run against an in-memory stand-in for the MongoCollection API, which moves into its own files.
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.
Summary
Horde_ActiveSync_State_Mongonow remembers which document its lock was taken on and releases the lock by that key, instead of deriving it from the state object's current sync key and collection.Fixes #117.
Builds on #116 (same methods in
State/Mongo.php); this PR only adds the last commit.Motivation
_stateRowLockQuery()builds the lock query from$this->_syncKeyand$this->_collection['id']. Both change before the lock is released:setNewSyncKey()sets the key of the state to be saved. The locked update in_saveSyncStateRow()then looked for the not yet existing document of the new key, matched nothing, and every save after a key advance failed withError saving state.The lock on the loaded document stayed until the stale timeout.loadState()sets the next sync key and collection before_loadState()releases the previous lock, so the lock of the previously loaded folder was never released (PING polling several folders).sync_folderid = nullwhilesave()stores'foldersync'.Changes
lib/Horde/ActiveSync/State/Mongo.php$_stateLockSyncKey, set in_acquireStateRowLock(), cleared on release._releaseStateRowLock()addresses the lock by_id = $_stateLockSyncKeyand the lock token._saveSyncStateRow(): the single conditional update is kept for a save under the loaded key. A save under another key goes through the insert path (including_recoverFromFailedStateInsert()from fix(activesync): keep sync state of two devices apart after a device change #116) and then releases the lock; the existing error handling releases it when the insert fails._stateFolderId(), used by_stateRowLockQuery()and_isOwnStateRow().No new catch blocks.
Tests
LockedDocumentTest.php: save under a new key, save under the loaded key, failed save under a new key, loading another folder, FOLDERSYNC load and save. Four of the five fail without the change.InMemoryMongoCollectionandInMemoryMongoDbmove fromDeviceChangeTest.phpinto their own files so both test classes can use them.RowLockTest.php,CollectionLockTest.php: the fixtures that fake a held lock also set the locked key.Not verified
None of this was run against a MongoDB server (none available). The defects were found by reading the code and reproduced against the in-memory stand-in for the legacy
MongoCollectionAPI; the stand-in only implements the query operators the state driver uses onHAS_state.Test plan
test/integration/Horde/ActiveSync/StateTest/Mongo: 19 tests pass, 23 tests that need a MongoDB server are skippedtest/unitsuite inside a Horde deployment: 425 tests, no new failures (4 existing, unrelated failures inAppointmentTest,FindRequestTest,Rfc822Test)