diff --git a/src/lib/md/SecurityIDRecorder.cpp b/src/lib/md/SecurityIDRecorder.cpp index ab85b1744..87cf50908 100644 --- a/src/lib/md/SecurityIDRecorder.cpp +++ b/src/lib/md/SecurityIDRecorder.cpp @@ -89,15 +89,39 @@ void SecurityIDRecorder::do_work() { work_db(); } +bool has_all_leg_keys(const MDProducerHandle& handle) { + if (handle.security().type == SecurityType::SECURITYTYPE_SPREAD) { + const FixedSpreadSecurityXL* pspread = static_cast(&handle.security()); + for (size_t x = 0; x < pspread->leg_count(); ++x) { + if (pspread->legs[x].key == invalid_security_key) { + return false; + } + } + } + // SyntheticFixedSecurity is guarunteed to have all of its legs + return true; +} + void SecurityIDRecorder::work_handles() { Security security; MDProducerHandle handle; + vector retry; while (_self->pending_handle.try_pop(handle)) { security.Clear(); - convert_security(handle.security(), &security); - assign_key(security, [handle](const api::Security& security) mutable { - handle.set_key(security.id()); - }); + // if a spread does not have all of its legs we need to wait + if (!has_all_leg_keys(handle)) { + retry.push_back(handle); + } + else { + convert_security(handle.security(), &security); + assign_key(security, [handle](const api::Security& security) mutable { + handle.set_key(security.id()); + }); + } + } + + for(const auto& h : retry) { + _self->pending_handle.push(h); } }