FuelLabs / FuelLabs/fuel-core

Properly handle the closing of the subscription

Open
#823 0 comments 0 reactions 0 assignees View on GitHub
graphql-api tech-debt
Dominant language
Rust
Stars
56.8k
Forks
2.9k
Avg merge
2d 9h
Merged PRs (30d)
5

Description

## Overview

The source is a pull request https://github.com/FuelLabs/fuel-core/pull/822.

While we support only one subscription(for transaction status), it is not a critical issue. Also, after https://github.com/FuelLabs/fuel-core/issues/588, it would be the responsibility of the indexer to provide subscription functionality. But if we will start adding more subscriptions on the `fuel-core` side before moving to the indexer, we need to resolve this issue.

## Issue

[`eventsource-client`](https://crates.io/crates/eventsource-client) library used for subscription(and seems [Server-Sent Events](https://html.spec.whatwg.org/multipage/server-sent-events.html) protocol) doesn't provide a built-in way to gracefully terminate a stream from the server side.

## Solution

Create a generic type `Event` and wrap all subscription types into this type. This type should answer the question, "Is that the last event?". Based on the answer, the server should close the connection. The client should use the same type to receive events and do the same check and close the connection if it is the last event.

It will prevent on the client side several useless iterations like reconnection and error logging and will provide a generic workflow over each subscription to not have this issue in the future.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing pull request #822 and the subscription code that uses the eventsource-client library. Trace how subscription events are sent and received, then define completion around the proposed generic Event type. Done means the server and client recognize the final event and close the connection without reconnection or error logging.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
api, backend-api-design
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.