Giter Club home page Giter Club logo

Comments (4)

indpurvesh avatar indpurvesh commented on May 30, 2024

I did some digging after so long I find that it is happening because of RwLock

How to get more then one writable session?

from axum-sessions.

Kokonoeqt avatar Kokonoeqt commented on May 30, 2024

i am having some issue with axum-sessions. WritableSession is just loading forever. But same Wrirable session works in my 3 handler function but for weird reason it just does not in one of my handler.

Does not work handler

pub async fn store_admin_user_handler(  
   mut session: WritableSession,  
   app_state: State<Arc<AppState>>,  
   Form(payload): Form<StoreAdminUserRequest>,  
) -> Result<impl IntoResponse, impl IntoResponse> { 
      Ok(Json(json!({})).into_response())  
 }

Below handler it works perfectly fine.

 pub async fn post_admin_login_handler(
     mut session: WritableSession,
     app_state: State<Arc<AppState>>,
     Form(payload): Form<LoginAdminUserRequest>,
 ) -> Result<impl IntoResponse, impl IntoResponse> { 
    Ok(Json(json!({})).into_response())  
  }

Omg I wish I seen this, I am literally facing same issue and was thinking of dropping the lock myself but if I have to manage the lock myself for more than one writable/readable session then I think it might be design issue?

Currently I have to do something like:

pub async fn auth_middleware_cookie<B>(
    State(state): State<AppState>,
    request: Request<B>,
    next: Next<B>,
) -> Response {
    tracing::info!("Auth middleware cookie");

    let session_handle = request.extensions().get::<SessionHandle>().unwrap().clone();

    tracing::info!("About to read from session handle");
    let session = session_handle.read().await;
    tracing::info!("Read from session handle completed");
    
    drop(session);
    tracing::info!("Calling next middleware");
    let response = next.run(request).await;
    tracing::info!("Response: {:?}", response);
    response
}

If I don't have the drop(session) it just never goes to the handler and hangs there causing it to timeout.

from axum-sessions.

maxcountryman avatar maxcountryman commented on May 30, 2024

Please see #50.

from axum-sessions.

indpurvesh avatar indpurvesh commented on May 30, 2024

@maxcountryman thanks for it. I did see that PR. Good works

from axum-sessions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.