shm: guard against pool destruction race condition

It might happen that a buffer is cached somewhere while the
pool has been set to null after a resize failed
This commit is contained in:
Christian Meissl 2024-05-16 21:04:28 +02:00
parent d763452a08
commit a6e96ce78a

View file

@ -116,6 +116,13 @@ impl InnerPool {
let pool_guard = self.map.read().unwrap();
// This should not happen, but in case a pool resize failed (which result in a protocol error
// and will kill the client) and the buffer got cached somewhere it is possible that we try to access
// a dead pool.
if pool_guard.ptr.is_null() {
return Err(());
}
trace!(fd = ?self.fd, "Buffer access on shm pool");
// Prepare the access
@ -152,6 +159,13 @@ impl InnerPool {
let pool_guard = self.map.write().unwrap();
// This should not happen, but in case a pool resize failed (which result in a protocol error
// and will kill the client) and the buffer got cached somewhere it is possible that we try to access
// a dead pool.
if pool_guard.ptr.is_null() {
return Err(());
}
trace!(fd = ?self.fd, "Mutable buffer access on shm pool");
// Prepare the access