Closed Lzzzzzt closed 2 months ago
strace with the code above(but switch to epoll for better observability):
epoll_create1(EPOLL_CLOEXEC) = 3
eventfd2(0, EFD_CLOEXEC|EFD_NONBLOCK) = 4
epoll_ctl(3, EPOLL_CTL_ADD, 4, {events=EPOLLIN|EPOLLRDHUP|EPOLLET, data={u32=2147483648, u64=2147483648}}) = 0
openat(AT_FDCWD, "test.txt", O_WRONLY|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 5
pwrite64(5, "Hello, world!", 13, 0) = 13
fsync(5) = 0
pread64(5, 0x58f06b7111f0, 13, 0) = -1 EBADF (Bad file descriptor)
write(1, "Err(Os { code: 9, kind: Uncatego"..., 73Err(Os { code: 9, kind: Uncategorized, message: "Bad file descriptor" })
) = 73
fcntl(5, F_GETFD) = 0x1 (flags FD_CLOEXEC)
close(5) = 0
close(3) = 0
fcntl(4, F_GETFD) = 0x1 (flags FD_CLOEXEC)
close(4)
EBADF should be about the open mode of the file.
After open it with read
(O_WRONLY
-> O_RDWR
), it shows expected result. The strace log is below:
epoll_create1(EPOLL_CLOEXEC) = 3
eventfd2(0, EFD_CLOEXEC|EFD_NONBLOCK) = 4
epoll_ctl(3, EPOLL_CTL_ADD, 4, {events=EPOLLIN|EPOLLRDHUP|EPOLLET, data={u32=2147483648, u64=2147483648}}) = 0
openat(AT_FDCWD, "test.txt", O_RDWR|O_CREAT|O_TRUNC|O_CLOEXEC, 0666) = 5
pwrite64(5, "Hello, world!", 13, 0) = 13
fsync(5) = 0
pread64(5, "Hello, world!", 13, 0) = 13
write(1, "Ok(13)\n", 7Ok(13)
) = 7
fcntl(5, F_GETFD) = 0x1 (flags FD_CLOEXEC)
close(5) = 0
close(3) = 0
fcntl(4, F_GETFD) = 0x1 (flags FD_CLOEXEC)
close(4) = 0
got it, it's not a bug, the std::fs::File
also act like this.
Thank you. @ihciah
Version
Platform
Description I am trying to implement
AsyncWriteRent/AsyncReadRent
formonoio::fs::FIle
, but when I write unit tests, I encountered an error:And I try the same code on the latest release, it will happen too.
Here is the minimum code to reproduce this error:
the file
test.txt
is successfully written with "Hello, world!", but can not read.