Skip to content

Subscription messages can silently fail to post back to client #250

@braudabaugh

Description

@braudabaugh

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:

_writer.Post(new OperationMessage

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs investigationThe described problem requires additional time to study

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions