happyborg,
@happyborg@fosstodon.org avatar

Calling #Rust web gurus.

I'm using the #reqwest crate to call two different APIs. One is working fine, the other I had working intermittently but not sure what fixed/unfixed it.

The issue is that the await doesn't return even though using curl works fine.

Why would await not return after a few seconds when the curl request returns immediately?

happyborg,
@happyborg@fosstodon.org avatar

This issue appears not to be a problem with the API or my code using #reqwest to access it.

The request stays pending indefinitely. I'm not sure why yet, that code is full of futures dragons, but it suggests that there may be a problem caused by how I'm using futures, maybe causing a deadlock under the hood.

Just guessing, but going to call the web API from the outer loop alongside the other futures threads rather than inside its own future, maybe use blocking
#async #Rust

happyborg,
@happyborg@fosstodon.org avatar

A timely blog from Tyler Mandry supports the possibility that my issue could arise from the way I'm using futures.

He mentions some facerakes which can occur using select! rather than merge! to combine futures so that's another avenue to pursue. Bonus: I will learn to produce more reliable async code.

Very interesting and commendable blog post on the state and future [cough] of #async #Rust:

https://tmandry.gitlab.io/blog/posts/making-async-reliable/

happyborg,
@happyborg@fosstodon.org avatar

As suspected the issue was not in the code I created to use remote web APIs.

The issue was that using the async function which polls the web APIs as a tokio::future was preventing the await on the web request from ever returning, even though the remote web API was responding correctly.

I fixed this by doing the polling of the my async function manually alongside the select! macro which handles the other two futures, all within a loop.

For my use case this fine. 😅
#Rust #async #futures

teotwaki,
@teotwaki@mastodon.online avatar

@happyborg Can you share code?

happyborg,
@happyborg@fosstodon.org avatar

@teotwaki

I'll be happy to in a day or two when I have the chance. But I wondered if there might be a reason why await might take time to return?

  • All
  • Subscribed
  • Moderated
  • Favorites
  • rust
  • DreamBathrooms
  • mdbf
  • ngwrru68w68
  • magazineikmin
  • thenastyranch
  • rosin
  • khanakhh
  • osvaldo12
  • Youngstown
  • slotface
  • Durango
  • kavyap
  • InstantRegret
  • tacticalgear
  • anitta
  • ethstaker
  • provamag3
  • cisconetworking
  • tester
  • GTA5RPClips
  • cubers
  • everett
  • modclub
  • megavids
  • normalnudes
  • Leos
  • JUstTest
  • lostlight
  • All magazines