diff --git a/src/geode/basic/uuid.cpp b/src/geode/basic/uuid.cpp index 69a04fed2..d572e20f7 100644 --- a/src/geode/basic/uuid.cpp +++ b/src/geode/basic/uuid.cpp @@ -239,9 +239,14 @@ namespace geode { uuid::uuid() { + static constexpr index_t MAX_SAFETY_COUNT = 1000; + static constexpr absl::Duration INITIAL_SLEEP = + absl::Microseconds( 100 ); + static constexpr absl::Duration MAX_SLEEP = absl::Milliseconds( 50 ); UUIDv7Generator gen; bool generated{ false }; - for( const auto i : Range{ 10 } ) + auto sleep = INITIAL_SLEEP; + for( const auto i : Range{ MAX_SAFETY_COUNT } ) { geode_unused( i ); if( auto bytes = gen.generate() ) @@ -250,6 +255,8 @@ namespace geode generated = true; break; } + absl::SleepFor( sleep ); + sleep = std::min( sleep * 2., MAX_SLEEP ); } OPENGEODE_EXCEPTION( generated, "[uuid] could not generate uuid" ); } @@ -316,4 +323,4 @@ namespace std { return absl::HashOf( uuid.bytes_ ); } -} // namespace std \ No newline at end of file +} // namespace std