Crash in URLConnectionState::run() while app is shutting down

I incurred a similar crash during the shutting down of a plugin that uses (the new) URLConnectionState. The crash doesn’t happen if you use the URLConnectionStatePreYosemite class. I’m using juce 7.0.9 on macOS.

I discovered the issue while building the VST3 during Update Manifest phase that starts the juce_vst3_helper and it loads the plugin.

To reproduce you can start with the basic plugin project and add these lines in the processor constructor

TestManifestVST3AudioProcessor::TestManifestVST3AudioProcessor()
{
    auto vpStream = juce::URL("https://www.google.com").createInputStream(juce::URL::InputStreamOptions(juce::URL::ParameterHandling::inAddress));
    if (vpStream)
    {
        DBG("STREAM EXISTS");
    }
    else
    {
        DBG("STREAM NULLPTR");
    }
}

The behavior is random, so I created a script to open several times the plugin using the juce_vst3_helper. Sometimes the error happens after > 100 trials…

vst3_manifest_tester.txt (543 Bytes)

PluginProcessor.cpp (6.6 KB)

I tried to debug it without success. I think it is related to the NSURLSession, NSURLSessionTask, and delegate management.