[ZEPPELIN-6462] Close interpreter-setting.json streams with try-with-resources - #5355
Open
big-cir wants to merge 1 commit into
Open
[ZEPPELIN-6462] Close interpreter-setting.json streams with try-with-resources#5355big-cir wants to merge 1 commit into
big-cir wants to merge 1 commit into
Conversation
…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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What is this PR for?
InterpreterSettingManagerdiscovers interpreters by reading each interpreter'sinterpreter-setting.json. Two helpers do this, and neither closes the stream it opens:The shared sink wraps the stream in an
InputStreamReaderand hands it togson.fromJson(...). Gson does not close a reader passed to it — the caller owns it — so the descriptor leaks on the normal path. There is nofinallyor try-with-resources either, so it also leaks when parsing throws, for example aJsonSyntaxExceptionfrom a malformed setting file.This is not limited to startup. After installing an interpreter through
POST /api/interpreter/install,InterpreterService.downloadInterpreter()callsrefreshInterpreterTemplates(), 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
registerInterpreterFromResourceregisterInterpreterFromPathWhat is the Jira issue?
How should this be tested?
Three tests were added to
InterpreterSettingManagerTest:testRegisterInterpreterFromPathClosesStreamtestRegisterInterpreterFromResourceClosesStreamtestStreamIsClosedWhenParsingFailsWith the try-with-resources reverted, all three fail:
With the fix in place:
Tests run: 14, Failures: 0.InterpreterFactoryTest,InterpreterSettingTestandInterpreterServiceTestalso pass (18 tests).Screenshots (if appropriate)
N/A
Questions: