firestore-db-and-auth-rs
firestore-db-and-auth-rs copied to clipboard
already mutably borrowed: BorrowError
Describe the bug
My program did stop with the following error:
thread 'tokio-runtime-worker' panicked at 'already mutably borrowed: BorrowError', /Users/yfleury/.cargo/registry/src/github.com-1ecc6299db9ec823/firestore-db-and-auth-0.6.1/src/sessions.rs:308:45
Looking at the sessions.rs
line (308 in the log, 488 in this repo source code) it seems that the call to .borrow()
is panicking.
I'm kind of new to Rust so I'm not sure everything is right on my side.
To Reproduce
Here is my program https://github.com/BearStudio/twitch-listener
Steps to reproduce the behavior:
- Run with
cargo run
- Use documents like
struct Question {
id: String,
username: String,
message: String,
timestamp: String,
}
Expected behavior
I expect my program not to panic.
Hi @yoannfleurydev, I am getting this same issue as well, did you ever find a solution?
Hi @yoannfleurydev, I am getting this same issue as well, did you ever find a solution?
Hi, no, not at this time sorry.
So I fixed the issue by reducing the scope of the borrows but for some reason it is still failing to renew the authorization, there doesn't seem to be any other errors in the process. This is all done through the standard ServiceSession that comes with the crate and works perfectly fine for the first hour.
pub mod service_account {
...
impl super::FirebaseAuthBearer for Session {
...
fn access_token(&self) -> String {
if jwt_update_expiry_if(&mut self.jwt.borrow_mut(), self.refresh_minutes) {
if let Some(secret) = self.credentials.keys.secret.as_ref() {
match self.jwt.borrow().encode(&secret.deref()) {
Ok(v) => {
match v.encoded() {
Ok(v2) => {
self.access_token_.swap(&RefCell::new(v2.encode()));
}
Err(e) => {
panic!("{:?}", e)
}
}
}
Err(e) => {
panic!("{}", e);
}
}
}
}
self.access_token_.borrow().clone()
}
}
}
After the hour has passed requests start returning APIError(401, "Request had invalid authentication credentials. Expected OAuth 2 access token, login cookie or other valid authentication credential.
. The panics never trigger either, there is no indication that the auth refresh failed. Could it be possible I am doing something wrong?
This is how my initialization looks:
impl Firestore {
pub fn new() -> Firestore {
let cred = Credentials::from_file("firebase-service-account.json")
.expect("Failed to load service file!");
let session = ServiceSession::new(cred, 59)
.expect("Failed to create session!");
Firestore {
session
}
}
}
@davidgraeff?
+1 having the same issue
Should be fixed. This is an RwLock now.