From b1e9525cf0080d45321d789f7c7efc6c96ffebae Mon Sep 17 00:00:00 2001 From: Tom Molesworth Date: Thu, 5 Sep 2024 12:01:35 +0800 Subject: [PATCH] Handle stream creation race condition --- lib/Myriad/Transport/Redis.pm | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/Myriad/Transport/Redis.pm b/lib/Myriad/Transport/Redis.pm index d6304ba5..ec8b1ecf 100644 --- a/lib/Myriad/Transport/Redis.pm +++ b/lib/Myriad/Transport/Redis.pm @@ -451,7 +451,15 @@ Then destroy that init consumer group. async method create_stream ($stream) { await $self->create_group($stream, 'INIT', '$', 1); - await $self->remove_group($stream, 'INIT'); + try { + await $self->remove_group($stream, 'INIT'); + } catch ($e) { + # If we have multiple instances, there's a race condition between creating the group + # and another instance trying to delete it before we get there. Ignore errors when + # that happens - we don't care who deleted the group, just that it goes away - but + # rethrow any other errors. + die $e unless $e =~ /NOGROUP/; + } $log->tracef('created a Redis stream: %s', $stream); }