-
Notifications
You must be signed in to change notification settings - Fork 6.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Prevent ClasspathResourceDirectoryReader from accessing closed NativeImageResourceFileSystem #30346
Conversation
746c40f
to
bd2af0f
Compare
@linghengqian Hi, I believe Stream can lazily consume resources. Are there any potential issues that I haven't considered? |
|
FileSystem resourceFileSystem = FileSystems.newFileSystem(directoryUrl.toURI(), Collections.emptyMap())
return loadFromDirectory(directoryUrl).onClose(resourceFileSystem::close()); Could this code resolve those problems? |
try (Stream<String> resourceNameStream = ClasspathResourceDirectoryReader.read(JDBCRepositorySQLLoader.class.getClassLoader(), ROOT_DIRECTORY)) {
Iterable<String> resourceNameIterable = resourceNameStream::iterator;
for (String each : resourceNameIterable) { |
The |
public void close() throws IOException {
beginWrite();
try {
if (!isOpen) {
return;
}
isOpen = false;
} finally {
endWrite();
}
if (!inputStreams.isEmpty()) { // Unlock and close all remaining input streams.
Set<InputStream> copy = new HashSet<>(inputStreams);
for (InputStream is : copy) {
is.close();
}
}
if (!outputStreams.isEmpty()) { // Unlock and close all remaining output streams.
Set<OutputStream> copy = new HashSet<>(outputStreams);
for (OutputStream os : copy) {
os.close();
}
}
provider.removeFileSystem();
} Alternatively, is it possible to consider not closing the resource file system? It seems that the close() method only closes some input/output streams, but I'm not very familiar with GraalVM. |
3a62733
to
46ee782
Compare
|
if ("resource".equals(directoryUrl.getProtocol())) { | ||
try (FileSystem ignored = FileSystems.newFileSystem(URI.create("resource:/"), Collections.emptyMap())) { | ||
try (FileSystem ignored = FileSystems.getFileSystem(directoryUrl.toURI())) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should a file system that has already been created not be closed?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- According to my understanding of JDBCRepositorySQLLoader native-image之后 loadFromDirectory方法,虽然进行了文件系统的创建,如果存在抛出java.nio.file.FileSystemAlreadyExistsException异常,没有考虑 #30344, if
FileSystems.getFileSystem()
does not throwjava.nio.file.FileSystemNotFoundException
, it means thatcom.oracle.svm.core.jdk.resources.NativeImageResourceFileSystem
is already in a third-party dependency life cycle, and additional judgments here are meaningless. - So I made my third commit. Call @huyu-tom .What do you think of this? This still doesn't break NativeTest.
4d77a89
to
875f5b8
Compare
Fixes #30345.
Changes proposed in this pull request:
Before committing this PR, I'm sure that I have checked the following options:
./mvnw clean install -B -T1C -Dmaven.javadoc.skip -Dmaven.jacoco.skip -e
.