Skip to content

[ZEPPELIN-6462] Close interpreter-setting.json streams with try-with-resources - #5355

Open
big-cir wants to merge 1 commit into
apache:masterfrom
big-cir:ZEPPELIN-6462
Open

[ZEPPELIN-6462] Close interpreter-setting.json streams with try-with-resources#5355
big-cir wants to merge 1 commit into
apache:masterfrom
big-cir:ZEPPELIN-6462

Conversation

@big-cir

@big-cir big-cir commented Jul 28, 2026

Copy link
Copy Markdown

What is this PR for?

InterpreterSettingManager discovers interpreters by reading each interpreter's interpreter-setting.json. Two helpers do this, and neither closes the stream it opens:

// registerInterpreterFromResource
getInterpreterListFromJson(url.openStream());

// registerInterpreterFromPath
getInterpreterListFromJson(new FileInputStream(interpreterJsonPath.toFile()));

The shared sink wraps the stream in an InputStreamReader and hands it to gson.fromJson(...). Gson does not close a reader passed to it — the caller owns it — so the descriptor leaks on the normal path. There is no finally or try-with-resources either, so it also leaks when parsing throws, for example a JsonSyntaxException from a malformed setting file.

This is not limited to startup. After installing an interpreter through POST /api/interpreter/install, InterpreterService.downloadInterpreter() calls refreshInterpreterTemplates(), which re-runs the whole directory scan. Every install therefore leaks one descriptor per interpreter directory, and the leaks accumulate on a long-running server.

This PR wraps each stream in a try-with-resources at the call site that opens it. Parsing and registration behaviour is unchanged.

What type of PR is it?

Bug Fix

Todos

  • Close the stream opened in registerInterpreterFromResource
  • Close the stream opened in registerInterpreterFromPath
  • Cover both the normal path and the parse-failure path with tests

What is the Jira issue?

How should this be tested?

Three tests were added to InterpreterSettingManagerTest:

  • testRegisterInterpreterFromPathClosesStream
  • testRegisterInterpreterFromResourceClosesStream
  • testStreamIsClosedWhenParsingFails
./mvnw package -pl zeppelin-server --am -Dtest=InterpreterSettingManagerTest -DfailIfNoTests=false

With the try-with-resources reverted, all three fail:

[ERROR] Tests run: 14, Failures: 3
  testRegisterInterpreterFromPathClosesStream      Wanted but not invoked: ...close()
  testRegisterInterpreterFromResourceClosesStream  Wanted but not invoked: ...close()
  testStreamIsClosedWhenParsingFails               Wanted but not invoked: ...close()

With the fix in place: Tests run: 14, Failures: 0.

InterpreterFactoryTest, InterpreterSettingTest and InterpreterServiceTest also pass (18 tests).

Screenshots (if appropriate)

N/A

Questions:

  • Does the license files need to update? No
  • Is there breaking changes for older versions? No
  • Does this needs documentation? No

…resources

Both registration paths handed a freshly opened InputStream to Gson
without closing it, and Gson does not close a reader passed to it. The
descriptor leaked on the normal path and on the parse-failure path
alike, and registration re-runs on every interpreter install.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant