Skip to content

Make sure files are closed correctly - #3023

Open
DavyLandman wants to merge 3 commits into
mainfrom
fix/missing-file-close
Open

DavyLandman wants to merge 3 commits into
mainfrom
fix/missing-file-close

Conversation

@DavyLandman

@DavyLandman DavyLandman commented Nov 27, 2026 •

Copy link
Copy Markdown
Member

Diagnosing usethesource/rascal-language-servers#1276 pointed to a file-handle leak in the ColumnMaps loader function. After that change I've reviewed all uses of getCharacterReader and getInputStream and fixed a few more cases. For example our class loader would leak file handles until the GC came around.

I also rewrite a few others to use try-with-resources just so that its clear it's always handled correctly (and reduces the code size around that ceremony of closing and catching the exceptions on close etc).

Fixes usethesource/rascal-language-servers#1276

@codecov

codecov Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 42.85714% with 12 lines in your changes missing coverage. Please review.
✅ Project coverage is 46%. Comparing base (48ef38e) to head (5447bac).
⚠️ Report is 11 commits behind head on main.

Files with missing lines Patch % Lines
src/org/rascalmpl/library/Prelude.java 0% 3 Missing ⚠️
src/org/rascalmpl/dap/RascalDebugAdapter.java 0% 2 Missing ⚠️
src/org/rascalmpl/library/lang/manifest/IO.java 0% 2 Missing ⚠️
src/org/rascalmpl/uri/URIResolverRegistry.java 0% 2 Missing ⚠️
...g/rascalmpl/values/RascalFunctionValueFactory.java 50% 2 Missing ⚠️
src/org/rascalmpl/library/lang/rsf/RSFIO.java 50% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##              main   #3023   +/-   ##
=======================================
  Coverage       46%     46%           
+ Complexity    6936    6935    -1     
=======================================
  Files          851     851           
  Lines        69360   69336   -24     
  Branches     10110   10104    -6     
=======================================
- Hits         32179   32174    -5     
+ Misses       34745   34728   -17     
+ Partials      2436    2434    -2     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@DavyLandman
DavyLandman marked this pull request as ready for review November 27, 2026 10:42
if (exists(file)) {
try {
byte[] bytes = Prelude.consumeInputStream(getInputStream(file));
try (var classContents = getInputStream(file)) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here is the bugfix for the class loader leaking input stream handle.

private static ColumnMaps initColumnMaps() {
return new ColumnMaps(loc -> {
return Prelude.consumeInputStream(URIResolverRegistry.getInstance().getCharacterReader(loc.top()));
try (var contents = URIResolverRegistry.getInstance().getCharacterReader(loc.top())) {

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the bugfix for the issue reported in rascal-language-servers

@PieterOlivier PieterOlivier left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice fixes and code cleanup by reusing existing methods.

@DavyLandman
DavyLandman force-pushed the fix/missing-file-close branch from 008e6fb to 5447bac Compare November 27, 2026 19:20
@sonarqubecloud

Copy link
Copy Markdown

@toinehartman toinehartman left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice safety improvements and code size reduction.

*/

public IInteger getFileLength(ISourceLocation g) {
if (g.getScheme().equals("file")) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we not need the special case for file anymore?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this all happens inside the URIResolverRegistry now. Automatically.

This branch has not been deployed

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Rascal-lsp keeps a handle on the on the pom.xml file, blocking a git pull

4 participants