mirror of
https://github.com/aljazceru/turso.git
synced 2026-02-06 08:44:23 +01:00
Fix io_uring WAL write corruption by ensuring buffer lifetime
Ensure the Arc<RefCell<Buffer>> in UringFile::pwrite remains alive until the io_uring write completes by referencing it in the completion callback. This prevents WAL file corruption where the correct buffer data was overwritten with stale memory (e.g., 00 18 27 xx instead of 37 7f 06 82). Validation: - Tested with limbo -v io_uring and WAL operations. - Verified with xxd and wal-browser. Signed-off-by: Daniel Boll <danielboll.academico@gmail.com>
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use super::{common, Completion, File, OpenFlags, IO};
|
||||
use super::{common, Completion, File, OpenFlags, WriteCompletion, IO};
|
||||
use crate::{LimboError, Result};
|
||||
use rustix::fs::{self, FlockOperation, OFlags};
|
||||
use rustix::io_uring::iovec;
|
||||
@@ -279,7 +279,14 @@ impl File for UringFile {
|
||||
.build()
|
||||
.user_data(io.ring.get_key())
|
||||
};
|
||||
io.ring.submit_entry(&write, c);
|
||||
io.ring.submit_entry(
|
||||
&write,
|
||||
Completion::Write(WriteCompletion::new(Box::new(move |result| {
|
||||
c.complete(result);
|
||||
// NOTE: Explicitly reference buffer to ensure it lives until here
|
||||
let _ = buffer.borrow();
|
||||
}))),
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user