Skip to content
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

Streams fetched by data-providers are never closed #18551

Closed
heruan opened this issue Jan 26, 2024 · 1 comment · Fixed by #18552
Closed

Streams fetched by data-providers are never closed #18551

heruan opened this issue Jan 26, 2024 · 1 comment · Fixed by #18552

Comments

@heruan
Copy link
Member

heruan commented Jan 26, 2024

Description of the bug

Let’s say I have a backend data-provider for a stream of strings read from a BufferedReader, e.g.

public Stream<String> fetchFromBackend(Query<String> query) {
    var reader = createBufferedReader();
    return reader.lines().skip(query.getOffset()).limit(query.getLimit()).onClose(reader::close);
}

In this case I want to be sure to close the reader when the stream reaches a terminal operation, so I do onClose(reader::close). Problem is, when the DataCommunicator gets that stream:

Stream<T> stream = getDataProvider().fetch(query);

then it is never closed. This also applies to the DataView API, e.g.
public Stream<T> getItems() {
return dataProviderSupplier.get().fetch(new Query<>());
}

Expected behavior

Upon calling terminal operations, the stream is then closed.

Minimal reproducible example

See code snippet in the description above.

Versions

  • Vaadin / Flow version: 24.4
  • Java version: 21
  • OS version: macOS 14.2.1
mcollovati pushed a commit that referenced this issue Jan 30, 2024
Fixes DataCommunicator API by handling the streams fetched from data-providers inside try-with-resources blocks.
Unclosed streams might still leak from the DataView API, that should be fixed in each component using that API.

Fixes #18551
vaadin-bot pushed a commit that referenced this issue Jan 30, 2024
Fixes DataCommunicator API by handling the streams fetched from data-providers inside try-with-resources blocks.
Unclosed streams might still leak from the DataView API, that should be fixed in each component using that API.

Fixes #18551
vaadin-bot added a commit that referenced this issue Jan 30, 2024
Fixes DataCommunicator API by handling the streams fetched from data-providers inside try-with-resources blocks.
Unclosed streams might still leak from the DataView API, that should be fixed in each component using that API.

Fixes #18551

Co-authored-by: Giovanni Lovato <giovanni@vaadin.com>
@vaadin-bot
Copy link
Collaborator

This ticket/PR has been released with Vaadin 24.3.4.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Development

Successfully merging a pull request may close this issue.

3 participants