Skip to content

tryFlushOutbox is not thread-safe #230

@jameshfisher

Description

@jameshfisher

As reported by a user in support (thanks!):

Steps to reproduce

Call some combination of registerWithDeviceToken, subscribe, and unsubscribe concurrently

Expected behavior

Eventually, all the subscribe/unsubscribe calls are processed in the order in which they were called

Actual behavior

This line ...

[outbox removeObjectAtIndex:0];

... crashes with the error:

*** Terminating app due to uncaught exception 'NSRangeException', reason: '*** -[__NSArrayM removeObjectAtIndex:]: index 0 beyond bounds for empty array'

Reason

(Hypothesized, not reproduced)

tryFlushOutbox is not threadsafe. Between lookup object at index 0, and then removing the object at index 0, things may have changed. This may happen if tryFlushOutbox is called multiple times: they will interfere with each other.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions