Safari Web Extension Handle Concurrency

We are building a Safari web extension utilising native messaging, to send messages to the Swift native part of the app. We sometimes experience, that the beginRequest handler is executed multiple times, at the same time.

We have a special part of the code in the handler, that must be run only once. Because it uses NS defaults storage, and also because it calls our servers. We have tried to use a serial dispatch queue, as well as other locking and mutex techniques, to no success.

We suspect that the instances of the handler are isolated in a way, that these locks don’t work (maybe they don’t share memory?). But we are not sure. When looking at os_logs from the handlers, they all share the same PID.

Has anyone experienced anything similar and can shed some light on what's going on?

Can you file a bug report and attach your sample, along with a sysdiagnose when the issue is occurring?

Safari Web Extension Handle Concurrency
 
 
Q