Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[edge case] Error during reconnect if the stream in the meantime is delete #335

Closed
Gsantomaggio opened this issue Dec 14, 2023 · 0 comments · Fixed by #344
Closed

[edge case] Error during reconnect if the stream in the meantime is delete #335

Gsantomaggio opened this issue Dec 14, 2023 · 0 comments · Fixed by #344
Assignees
Labels
bug Something isn't working

Comments

@Gsantomaggio
Copy link
Member

Describe the bug

This bug occurs when a stream is deleted while the Consumer is trying to re-connect.
In most of case it works because the Metadata does the check.

but during the check and restart of the consumer, the stream could be deleted. [here the edge case]

Unhandled exception. RabbitMQ.Stream.Client.CreateConsumerException: consumer could not be created code: StreamDoesNotExist
   at RabbitMQ.Stream.Client.StreamSystem.CreateRawConsumer(RawConsumerConfig rawConsumerConfig, ILogger logger) in //rabbitmq-stream-dotnet-client/RabbitMQ.Stream.Client/StreamSystem.cs:line 441
   at RabbitMQ.Stream.Client.Reliable.ConsumerFactory.StandardConsumer(Boolean boot) in //rabbitmq-stream-dotnet-client/RabbitMQ.Stream.Client/Reliable/ConsumerFactory.cs:line 80
   at RabbitMQ.Stream.Client.Reliable.ConsumerFactory.CreateConsumer(Boolean boot) in //rabbitmq-stream-dotnet-client/RabbitMQ.Stream.Client/Reliable/ConsumerFactory.cs:line 33
   at RabbitMQ.Stream.Client.Reliable.Consumer.CreateNewEntity(Boolean boot) in //rabbitmq-stream-dotnet-client/RabbitMQ.Stream.Client/Reliable/Consumer.cs:line 186
   at RabbitMQ.Stream.Client.Reliable.ReliableBase.Init(Boolean boot, IReconnectStrategy reconnectStrategy) in //rabbitmq-stream-dotnet-client/RabbitMQ.Stream.Client/Reliable/ReliableBase.cs:line 89
   at RabbitMQ.Stream.Client.Reliable.ReliableBase.Init(IReconnectStrategy reconnectStrategy) in //rabbitmq-stream-dotnet-client/RabbitMQ.Stream.Client/Reliable/ReliableB

Reproduction steps

  1. Run multi consumers
  2. Delete the streams

Most of the time it works but it could happen that the stream is deleted just after the check streamExist

...

Expected behavior

Close the consumer.
Need to check the error code: ConsumerFactory::StandardConsumer When it is not the first boot. If there is an error just close the consumer.

Same for Producer

Additional context

No response

@Gsantomaggio Gsantomaggio added the bug Something isn't working label Dec 14, 2023
@Gsantomaggio Gsantomaggio self-assigned this Dec 14, 2023
Gsantomaggio added a commit that referenced this issue Jan 18, 2024
Fixes: #333
Fixes: #335

# Preface
The commit is focused on making the client more stable during the server restart and better handling the metadata update event.

Most of the changes are in the super stream producer and consumer.
See the issue #333

# 1- What's changed in the super stream part


The RawSuperStreamProducer and RawSuperStreamConsumer expose two callbacks:
- `ConnectionClosedHandler (reason, stream)` 
- `MetadataHandler(update)` 
- `ISuperStreamProducer` and `ISuperStreamConsumer` interfaces 

ConnectionClosedHandler
--
The callback is raised each time a partition is closed for some reason. You can check the reason with:
```
1- public const string Normal = "TCP connection closed normal";
2- public const string Unexpected = "TCP connection closed unexpected";
```

1- The super stream partition is closed by the `Close()` method, so there are no problems. It can be helpful in terms of alerting or logs.

2- The super stream partition is closed in an unexpected way like kill the connection, network problems broker restart etc..

In that case, you can reconnect the partition with the `ReconnectPartition` method.

MetadataHandler
---
It happens when there is a change in the stream topology.

In this case, the server drops all the producers and consumers. So, you need to react to the Metadata Handler event.  You can decide to reconnect the producer and consumer
using the `ReconnectPartition` 

Producer and Consumer classes
--

The `Producer` and `Consumer` classes handle automatically the `ConnectionClosedHandler` and the `MetadataHandler` events for stream and super stream.


# 2- Fail fast

The Producer and Consumer classes can restore the connection automatically when they are up and running.
The classes will fail immediately if there are problems during the first connection.
This behaviour is now like the Java Client's.


---------

Signed-off-by: Gabriele Santomaggio <G.santomaggio@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant