server: Subscription messages can silently fail to post back to client
When generating subscription messages in rapid succession, some messages may never make it back to the client. I’ve debugged the issue to the Subscription.OnNext function calling _writer.Post here:
The call to _writer.Post returns false when the messages are lost. A false return value is meant to indicate that the Post could not be completed without blocking, but the Subscription.OnNext function does not handle this case.
My solution is to use _write.SendAsync instead, as it will send the messages even if it must block. Here are my implementation of Subscription.OnNext:
public void OnNext(ExecutionResult value)
{
_logger.LogDebug("Subscription: {subscriptionId} got data", Id);
var task = Task.Run(() => _writer.SendAsync(new OperationMessage
{
Type = MessageType.GQL_DATA,
Id = Id,
Payload = value
}));
task.Wait();
}
I am not sure if this is the best solution, but it is working for my use case.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 35 (13 by maintainers)
@sungam3r @pekkah This seems like an absolutely critical bug that we should fix asap. Of course it only applies to subscriptions, but that is a foundational part of graphql. Do you want me to investigate and review the existing PR?
@jinhong- Can you fix the merge conflicts in your PR? Are you still using the code successfully?
Nowadays TGQL supports both. The additional burden of SignalR is that it requires client side library also to make it work with Apollo.