Problems keeping the session active

Hi Guys, How are you doing?

I am developing a rest api that consumes the Jira API, so I have a session.rs model that when instantiating the structure, it performs authentication

//session.rs

pub struct SessionManager {
    client: Client,
    pub base_url: Url,
    pub cookie: Option<String>,
    pub base64_auth: Option<String>,
}

impl SessionManager {
    pub async fn new() -> Result<Self> {
        let client = Client::new();
        let base_url = Url::parse("https://hermes.gcsec.net").map_err(|e| anyhow!("Parse URL Failed: {}", e))?;

        info!("Instancing Session");
        let (cookie, base64_auth) = Self::authenticate(&client, &base_url).await?;

        Ok(SessionManager {
            client,
            base_url,
            cookie: Some(cookie),
            base64_auth: Some(base64_auth),
        })
    }

What is happening is, when starting the cargo run application, it connects, shows the connection that got cookies and all that, but when making the request to an endpoint, it shows 401 Status.

This is something intermittent if I keep restarting, eventually the endpoint works and the data arrives.

I tested this in two web frameworks, actix and rocket.rs and using the session State.

Now if I don't use a framework, I can keep restarting the application and there is no such "intermittent" problem.

I would like some suggestions on how to understand and debug

Thanks

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.