From 9786e6035fd5e8daf007adc3c37abcef6d6cc05e Mon Sep 17 00:00:00 2001 From: Robin Gareus Date: Sun, 26 Oct 2025 15:10:46 +0100 Subject: [PATCH] Fix crash due to concurrent sndfile access Peak files are built int background which can happen concurrently to estimating tempo. Notably when importing large .flac files this can cause a crash because libsndfile API does not allow for concurrent use of the same SNDFILE object. --- libs/ardour/audiosource.cc | 3 +++ libs/ardour/source_factory.cc | 15 ++++++++++++--- 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/libs/ardour/audiosource.cc b/libs/ardour/audiosource.cc index aceb0d7036..73dae08c42 100644 --- a/libs/ardour/audiosource.cc +++ b/libs/ardour/audiosource.cc @@ -135,7 +135,10 @@ AudioSource::~AudioSource () void AudioSource::estimate_tempo () { +#ifndef NDEBUG /* CALLER MUST HOLD WRITER LOCK */ + assert (!_lock.writer_trylock()); +#endif const samplecnt_t ten_seconds = _session.sample_rate() * 10; diff --git a/libs/ardour/source_factory.cc b/libs/ardour/source_factory.cc index 1e316ad4d2..d5c19635f5 100644 --- a/libs/ardour/source_factory.cc +++ b/libs/ardour/source_factory.cc @@ -259,7 +259,10 @@ SourceFactory::createExternal (DataType type, Session& s, const string& path, throw failed_constructor (); } ret->check_for_analysis_data_on_disk (); - src->estimate_tempo (); + { + Source::WriterLock lm (src->mutex ()); + src->estimate_tempo (); + } if (announce) { SourceCreated (ret); } @@ -276,7 +279,10 @@ SourceFactory::createExternal (DataType type, Session& s, const string& path, throw failed_constructor (); } ret->check_for_analysis_data_on_disk (); - src->estimate_tempo (); + { + Source::WriterLock lm (src->mutex ()); + src->estimate_tempo (); + } if (announce) { SourceCreated (ret); } @@ -425,7 +431,10 @@ SourceFactory::createFromPlaylist (DataType type, Session& s, std::shared_ptrcheck_for_analysis_data_on_disk (); - src->estimate_tempo (); + { + Source::WriterLock lm (src->mutex ()); + src->estimate_tempo (); + } SourceCreated (ret); return ret; }