A better Rust ATProto crate

Setting base_uri on XrpcClient causes panic with tokio current_thread #12

closed
opened by her.dog

When XrpcClient's base_uri setter is called (at least on the OAuthSession implementation), tokio will panic when using the current_thread flavor with the error message can call blocking only when running on the multi-threaded runtime.

The snippet that causes the panic is:

fn base_uri(&self) -> Url {
    // base_uri is a synchronous trait method; we must avoid async `.read().await`.
    // Use `block_in_place` under Tokio runtime to perform a blocking RwLock read safely.
    #[cfg(not(target_arch = "wasm32"))]
    if tokio::runtime::Handle::try_current().is_ok() {
        return tokio::task::block_in_place(|| self.data.blocking_read().host_url.clone());
    }

    self.data.blocking_read().host_url.clone()
}

This can be reproduced by implementing a basic OAuth flow as described in the docs and using #[tokio::main(flavor = "current_thread")]

good catch. i'm not happy with that bit of code. would you prefer i make the method async to match the underlying storage? the block was a stopgap i knew i would have to deal with eventually.

Made the base_uri() method async, which should resolve this.

yea this is ideal - thanks!

sign up or login to add to the discussion
Labels

None yet.

assignee

None yet.

Participants 2
AT URI
at://did:plc:p5yjdr64h7mk5l3kh6oszryk/sh.tangled.repo.issue/3m3fgxoll6n22