You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Describe the bug
Suppose a simple usecase where you need to accept HTTP request, subscribe to event, and send HTTP response when an event occurs:
public async Task<ActionResult> ControllerMethod() {
var tcs = new TaskCompletionSource<T>();
using (await _eventStoreConnection.SubscribeToStreamAsync(streamName, true, (_, @event) => {
tcs.TrySetResult(@event);
}, (_, __, ex) => {
if (ex != null) tcs.TrySetException(ex);
})) {
return Ok(await tcs.Task);
}
}
Now, if EventStore will temporarily go down, the default 10 reconnection retries will run out, and the connection will become unusable, given it is registered as a singleton. The solution here is to specify KeepRetrying when constructing ConnectionSettings, but now another problem arises - SubscribeToStreamAsync ignores LimitRetriesForOperationTo, when the target EventStore node experiences outage. So the client request will hang until the connection is restored. Even more, the client might timeout and decide to abort the request and retry. We must handle that case and have CancellationToken passed all the way down from the controller, but SubscribeToStreamAsync does not provide the ability for cooperative cancellation!
public async Task<ActionResult> ControllerMethod(CancellationToken token) {
var tcs = new TaskCompletionSource<T>();
using (cancellationToken.Register(() => tcs.TrySetCanceled(cancellationToken)))
using (await _eventStoreConnection.SubscribeToStreamAsync(streamName, true, (_, @event) => {
tcs.TrySetResult(@event);
}, (_, __, ex) => {
if (ex != null) tcs.TrySetException(ex);
}/* No parameter for cancellation token! */)) {
return Ok(await tcs.Task);
}
}
Is this intended, and if so, how do you recommend implementing fault-tolerant subscription, that timeouts in case of node failure?
Code to reproduce
var s = ConnectionSettings.Create()
.KeepReconnecting()
.Build();
// There is no EventStore on localhost:2305
var conn = EventStoreConnection.Create(s, new Uri("tcp://localhost:2305"));
await conn.ConnectAsync();
// We hang forever here
await conn.SubscribeToStreamAsync("stream", true, (subscription, @event) =>
{
return Task.CompletedTask;
});
Expected behavior SubscribeToStreamAsync throws ConnectionClosedException after operation retry limit exceeded, and provides CancellationToken argument to cancel operation
Actual behavior SubscribeToStreamAsync hangs forever in case of EventStore outage, and can not be cancelled from outside
Config/Logs/Screenshots
This batch of log entries appears in the log in an endless loop
Describe the bug
Suppose a simple usecase where you need to accept HTTP request, subscribe to event, and send HTTP response when an event occurs:
Now, if EventStore will temporarily go down, the default 10 reconnection retries will run out, and the connection will become unusable, given it is registered as a singleton. The solution here is to specify
KeepRetrying
when constructingConnectionSettings
, but now another problem arises -SubscribeToStreamAsync
ignoresLimitRetriesForOperationTo
, when the target EventStore node experiences outage. So the client request will hang until the connection is restored. Even more, the client might timeout and decide to abort the request and retry. We must handle that case and haveCancellationToken
passed all the way down from the controller, butSubscribeToStreamAsync
does not provide the ability for cooperative cancellation!Is this intended, and if so, how do you recommend implementing fault-tolerant subscription, that timeouts in case of node failure?
Code to reproduce
Expected behavior
SubscribeToStreamAsync
throwsConnectionClosedException
after operation retry limit exceeded, and providesCancellationToken
argument to cancel operationActual behavior
SubscribeToStreamAsync
hangs forever in case of EventStore outage, and can not be cancelled from outsideConfig/Logs/Screenshots
This batch of log entries appears in the log in an endless loop
EventStore details
EventStore server version: 4.1.0
Operating system: Ubuntu 18.04
EventStore client version: 5.0.1
The text was updated successfully, but these errors were encountered: