Report JDK bug: Direct I/O on Windows leaks a file handle (setDirect0 ReOpenFile)
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 35/100
- Loại issue
- Lỗi
- Độ rõ ràng
- Đặc tả rõ ràng
- Mức độ hoạt động
- Sôi nổi
- Lĩnh vực
- operating-systems
Hướng nghiên cứu
The leak is in src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c, where the handle from ReOpenFile is never closed before setDirect0 returns; the reproduction is the DirectLeak4.java program in the issue body. The remaining work is outside the repository: search the OpenJDK bug tracker for an existing report, file one at bugreport.java.com under core-libs / java.nio, then record the bug ID in this issue and in the #257 comments. Done means the report exists and its ID is linked here.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Track filing an OpenJDK bug report for the Windows Direct I/O handle leak found in #257 (worked around in #259).
Summary
On Windows, every FileChannel.open(..., ExtendedOpenOption.DIRECT) leaks a file handle. sun.nio.ch.FileDispatcherImpl.setDirect0() opens a second handle with ReOpenFile() to query the sector size and never closes it.
src/java.base/windows/native/libnio/ch/FileDispatcherImpl.c (same in the JDK 25 tag and current master):
HANDLE modify = ReOpenFile(orig, 0, 0,
FILE_FLAG_NO_BUFFERING | FILE_FLAG_WRITE_THROUGH);
if (modify != INVALID_HANDLE_VALUE) {
... GetDiskFreeSpaceW(lpRootPathName, ...) ...
result = bytesPerSector;
}
return result; // `modify` is never closed
Suggested fix: CloseHandle(modify); before returning.
Impact
- The leaked handle (access
0x100080,SYNCHRONIZE | FILE_READ_ATTRIBUTES) stays open until the JVM exits; one per Direct I/O open. - FAT32 / exFAT: a deleted file stays pending delete until its last handle closes, so the file can't be re-created or opened (
AccessDeniedException) and its folder can't be removed until the JVM exits. - NTFS: deletion still works (the name is removed immediately), but handles still accumulate.
Test results (JDK 25.0.1, Windows 11)
| Drive | DIRECT open only / write / read | Buffered | Raw Win32 FILE_FLAG_NO_BUFFERING + CloseHandle |
|---|---|---|---|
| FAT32 (USB) | recreate after delete: AccessDeniedException | OK | OK |
| exFAT (USB) | recreate after delete: AccessDeniedException | — | — |
| NTFS | OK | OK | — |
The raw Win32 result shows Windows handles unbuffered files correctly; the leak is in the JDK.
Reproduction
Run with java DirectLeak4.java <file on FAT32/exFAT drive> <wopen|write|read>, e.g. java DirectLeak4.java E:\leak.dat wopen. Expected recreate=OK, actual recreate=FAILED AccessDeniedException.
import com.sun.nio.file.ExtendedOpenOption;
import java.lang.foreign.*;
import java.nio.channels.FileChannel;
import java.nio.file.*;
import java.util.*;
public class DirectLeak4 {
public static void main(String[] a) throws Exception {
Path p = Path.of(a[0]); String mode = a[1]; int n = 7; int bs = 512 * 1024;
Files.write(p, new byte[bs * n]);
try (Arena arena = Arena.ofConfined()) {
MemorySegment seg = arena.allocate(bs, 4096);
for (int i = 0; i < n; i++) {
switch (mode) {
case "wopen" -> { try (FileChannel fc = FileChannel.open(p, StandardOpenOption.WRITE, ExtendedOpenOption.DIRECT)) { } }
case "write" -> { try (FileChannel fc = FileChannel.open(p, StandardOpenOption.WRITE, ExtendedOpenOption.DIRECT)) { fc.write(seg.asByteBuffer(), (long) i * bs); } }
case "read" -> { try (FileChannel fc = FileChannel.open(p, StandardOpenOption.READ, ExtendedOpenOption.DIRECT)) { fc.read(seg.asByteBuffer(), (long) i * bs); } }
}
}
}
System.out.println("READY"); System.out.flush();
Thread.sleep(5000);
Files.delete(p);
try { FileChannel.open(p, StandardOpenOption.CREATE, StandardOpenOption.WRITE).close(); System.out.println("recreate=OK"); Files.deleteIfExists(p); }
catch (Exception e) { System.out.println("recreate=FAILED " + e.getClass().getSimpleName()); }
}
}
To do
- Search the OpenJDK bug tracker for an existing report (none found so far).
- File at https://bugreport.java.com (component: core-libs / java.nio) with the analysis and reproduction above.
- Add the JDK bug ID here and in the #257 workaround comments; remove the workaround once a fixed JDK is the minimum.
- Ngôn ngữ chính
- Java
- Star
- 6
- Fork
- 6
- Merge trung bình
- 10 giờ 11 phút
- Pull request đã merge (30 ngày)
- 12
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của JDiskMark/jdm-java
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement linux
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
Maintainer thường phản hồi trong vòng 1 ngày
-
documentation linux
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Publish JDiskMark on FlathubĐang mởenhancement linux
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 35/100
Maintainer thường phản hồi trong vòng 1 ngày
-
bug linux
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 52/100
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của JDiskMark/jdm-java
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 2 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
bloxbean/yaci-store#1445 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
图片灯箱过长的话底部carousel滑动没有惯性Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
-
Spare PermissionĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 63/100
Etar-Group/Etar-Calendar#2234 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
[BUG] MCP resources-as-tools drops invocation context when listing templatesCó thể đã có người làm @CryoThrust đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
langchain4j/langchain4j#7320 ·
Maintainer thường phản hồi trong vòng 1 ngày