fix(postgres): make advisory lock cancel safe#4199
fix(postgres): make advisory lock cancel safe#4199joeydewaal wants to merge 2 commits intolaunchbadge:mainfrom
Conversation
| pub async fn acquire<C: AsMut<PgConnection>>(&self, conn: C) -> Result<PgAdvisoryLockGuard<C>> { | ||
| // We're wrapping the connection in a `PgAdvisoryLockGuard` early here on purpose. If this | ||
| // future is dropped, the lock will be released in the drop impl. | ||
| let mut guard = PgAdvisoryLockGuard::new(self.clone(), conn); |
There was a problem hiding this comment.
Won't this also cause us to release the lock on drop before it's even been acquired? Is that OK?
There was a problem hiding this comment.
Ah nvm, I assume anything done before the first await happens atomically.
There was a problem hiding this comment.
Actually, is it possible that the first await yields before actually managing to send the lock query? Like maybe if the TCP send buffer is full?
There was a problem hiding this comment.
Yeah the future can be dropped before it's actually sent out. But then it's in the write buffer, which is flushed the next time before the connection is used.
I guess the worst case would be when the query isn't prepared. Then the drop is going to queue an unnecessary release. Thanks for calling this out.
|
Note: I've decided to not update the |
This pr makes the
PgAdvisoryLock::acquirecancel safe by wrapping the connection in aPgAdvisoryLockbefore actually acquiring the lock. If theacquirefuture is dropped the drop impl will release the lock.Does your PR solve an issue?
fixes #4198
Is this a breaking change?
Nope