js-stellar-sdk icon indicating copy to clipboard operation
js-stellar-sdk copied to clipboard

Support for Abort Controller

Open aristidesstaffieri opened this issue 7 months ago • 1 comments

Is your feature request related to a problem? Please describe. In some scenarios where you call an sdk method that uses the http client under the hood, it's hard to cancel requests in order to avoid race conditions. One specific scenario is a user driven text input where the input expected is a federated address. The client can validate that the string is a valid federated address and that the sub string after the * is a valid domain, but if the user type is valid address, lets say aristides.staffieri*lobstr.co quickly followed by an invalid one like aristides.staffieri*lobstr.com then it would be nice to pass Federation.Server.resolve and abort controller in order to deal with the requests in flight.

Describe the solution you'd like functions that use an http client can take an options argument that includes an abort signal from the consuming client, then they pass that down to the underlying http client.

Describe alternatives you've considered Either keeping a request counter in my scope to track the in flight requests or writing my own federation address resolver that accepts an abort controller.

Additional context Here is where this issue can happen in Freighter. It's pretty edge case and requires a specific order of input values but still possible as a race condition.

aristidesstaffieri avatar Jun 09 '25 19:06 aristidesstaffieri

tfw people actually use FederationServer

This is already possible for Horizon if you use axios because its instance is exported from the library and supports AbortController which you can hook in via an interceptor, so it should be fairly easy to do the same thing in that module as well 🤔

Shaptic avatar Aug 05 '25 18:08 Shaptic