Skip to content
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

chore(webapp): Bump axum-login dependency to 0.13.1 #2118

Merged
merged 1 commit into from
Feb 29, 2024

Conversation

holzeis
Copy link
Contributor

@holzeis holzeis commented Feb 28, 2024

Not being super optimistic, but maybe the latest axum-login release fixes the issue with the randomly unresponsive webapp (#1938)

It looks like axum-login had issues with deadlocks in the past, but with tower-sessions those deadlock should have been fixed. Bumping from 0.12 to 0.13.1 also bumps the tower-session dependency. So this might help 🤞.

@holzeis holzeis requested review from bonomat and luckysori February 28, 2024 16:03
@holzeis holzeis self-assigned this Feb 28, 2024
@bonomat bonomat added this pull request to the merge queue Feb 29, 2024
@bonomat
Copy link
Contributor

bonomat commented Feb 29, 2024

sending to merge to give this a try right away.

Merged via the queue into main with commit 1ca5d53 Feb 29, 2024
21 checks passed
@bonomat bonomat deleted the chore/bump-axum-login-dependency branch February 29, 2024 01:59
@holzeis holzeis linked an issue Feb 29, 2024 that may be closed by this pull request
@maxcountryman
Copy link

Hey @holzeis, sorry to drop in unannounced: I was looking at the impl of the session store here and noticed you all using a synchronous lock.

Maybe I'm misunderstanding here, but is this meant to be used in production? If so, I would be concerned that a synchronous lock within a store might directly lead to e.g. deadlocks.

Is there a reason to not use tokio::sync::RwLock instead?

@luckysori
Copy link
Contributor

Hey @holzeis, sorry to drop in unannounced: I was looking at the impl of the session store here and noticed you all using a synchronous lock.

Maybe I'm misunderstanding here, but is this meant to be used in production? If so, I would be concerned that a synchronous lock within a store might directly lead to e.g. deadlocks.

Is there a reason to not use tokio::sync::RwLock instead?

Hey, @maxcountryman! Thanks for taking the time to look at our code and offer some advice.

I think you are absolutely right. At some point we spent a lot of time auditing the code base for instances of blocking code in an async context, but it seems like this has slipped code review.

Thanks again!

@luckysori
Copy link
Contributor

@maxcountryman: I've been giving it a bit more thought and I now think this code is actually fine! Maybe you can correct me if I'm wrong though.

I am pretty sure the common advice is to avoid using async Mutex/RwLock unless strictly necessary12. That is, if you need to hold it across an await point. The reason given is that async locks are considerably slower.

As far as I can tell, we are not actually holding the RwLock across an await point here.

What do you think?

Footnotes

  1. https://tokio.rs/tokio/tutorial/shared-state.

  2. https://draft.ryhl.io/blog/shared-mutable-state.

@maxcountryman
Copy link

While you're absolutely correct you generally don't need async locks, this is an example of the use case tokio calls out for async locks:

The primary use case for the async mutex is to provide shared mutable access to IO resources such as a database connection. 1

Granted, we have a HashMap here, but the session store is used as though it is non-blocking and same principle should apply.

In your second link, Alice mentions:

In my experience, the best way to avoid the above issue is to never lock the mutex in async code in the first place. Instead, you define non-async methods on the wrapper struct and lock the mutex there. Then, you call those non-async methods from your async code.

Emphasis mine. Observe that our blocking code is inside the async methods of the session store API and so we might be leading ourselves into trouble.

More specifically multiple tasks may load and save but this is impossible when we've blocked on a synchronous lock.

Footnotes

  1. https://docs.rs/tokio/latest/tokio/sync/struct.Mutex.html#which-kind-of-mutex-should-you-use

@Restioson
Copy link
Contributor

We could be causing it ourselves in delete_expired, since we lock the sessions for reading and then for writing later without dropping the guard - we are going to look into this imminently but I'm just putting a pin in it here so I don't forget!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Web app randomly stops responding
5 participants