Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crashes when encoding user models #1412

Merged
merged 7 commits into from
Apr 29, 2024

Commits on Apr 19, 2024

  1. add test reproducing crash when encoding models with concurrency

    * Adds two tests that encode Identity Model and Properties Model while their aliases and tags dictionary are written to.
    * The tests try to add data, clear data, and encode these models concurrently
    nan-li committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    35f6ed8 View commit details
    Browse the repository at this point in the history
  2. lock access to model dictionaries during encode

    * Identity Model and Properties Model have access to their aliases and tags dictionary wrapped in a lock. However, this lock was missing from the encode method, and is necessary.
    nan-li committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    8cdf446 View commit details
    Browse the repository at this point in the history
  3. No need to hydrate identity model twice

    * I noticed we were always hydrating the same identity model twice.
    * This is because we are parsing a fetch user response, we end up hydrating the identity model twice, unnecessarily, which drives caching it twice as well.
    * We already hydrate the identity model attached to the request.
    * Here, we were hydrating it again if the current user is the same. However, if the current user is the same, the model is the same and has already been hydrated.
    nan-li committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    8c28fba View commit details
    Browse the repository at this point in the history
  4. Update Identity Model to cache itself less frequently

    * Removing multiple aliases via `removeAliases(array)` will now be done in one go:
      - Creates one OSDelta that will be parsed by the executor into individual Remove Alias Requests
      - Caches the new aliases once instead of in a loop for each label to remove
    * Hydrating aliases will now be done in one go as well:
      - Now, cache the new aliases once at the end. Prior, we cache the aliases after each alias as we hydrate.
    * In addition, put the call to `self.set` outside of the tagsLock, since the call to `self.set` will drive encoding itself, which also requires the tagsLock. The UnfairLock does not handle nested locking.
    nan-li committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    ff4705a View commit details
    Browse the repository at this point in the history
  5. Use a recursive lock

    * Drop UnfairLock and use NSRecursiveLock
    * UnfairLock is fast, but it doesn’t support recursive locking. So, it crashes whenever you lock it twice from the same thread.
    * So far, we haven't encountered this, but this is possible, especially if we are not careful about how changes are propagated up.
    nan-li committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    ac60efc View commit details
    Browse the repository at this point in the history
  6. Move properties model's change propagation outside of the lock

    * Keep the lock minimal, just around write and read access to the tags dictionary
    * Move the events-driving outside of the lock, that create Deltas and caches the model, etc.
    nan-li committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    db031ff View commit details
    Browse the repository at this point in the history
  7. [dev app] add remove tag

    * Adding tags with blank value will remove the tag
    nan-li committed Apr 19, 2024
    Configuration menu
    Copy the full SHA
    98908ee View commit details
    Browse the repository at this point in the history