Skip to content

already mutably borrowed: BorrowError #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yoannfleurydev opened this issue Nov 7, 2021 · 5 comments
Closed

already mutably borrowed: BorrowError #30

yoannfleurydev opened this issue Nov 7, 2021 · 5 comments
Labels
bug Something isn't working

Comments

@yoannfleurydev
Copy link

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.

image

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:

  1. Run with cargo run
  2. Use documents like
struct Question {
    id: String,
    username: String,
    message: String,
    timestamp: String,
}

Expected behavior

I expect my program not to panic.

@yoannfleurydev yoannfleurydev added the bug Something isn't working label Nov 7, 2021
@blessedbythestorm
Copy link

Hi @yoannfleurydev,
I am getting this same issue as well, did you ever find a solution?

@yoannfleurydev
Copy link
Author

Hi @yoannfleurydev,
I am getting this same issue as well, did you ever find a solution?

Hi, no, not at this time sorry.

@blessedbythestorm
Copy link

blessedbythestorm commented Mar 13, 2022

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?

@redvg
Copy link

redvg commented Mar 31, 2022

+1
having the same issue

@davidgraeff
Copy link
Owner

Should be fixed. This is an RwLock now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants