Skip to content

Fix: Prevent resource leakage in SchemaFieldExtractor and FeedRepository#27449

Open
aniruddhaadak80 wants to merge 1 commit intoopen-metadata:mainfrom
aniruddhaadak80:fix-silent-exceptions-and-resource-leaks-27062
Open

Fix: Prevent resource leakage in SchemaFieldExtractor and FeedRepository#27449
aniruddhaadak80 wants to merge 1 commit intoopen-metadata:mainfrom
aniruddhaadak80:fix-silent-exceptions-and-resource-leaks-27062

Conversation

@aniruddhaadak80
Copy link
Copy Markdown

@aniruddhaadak80 aniruddhaadak80 commented Apr 17, 2026

Resolves issue #27062. Surfaced a mistakenly swallowed generic Exception within FeedRepository thread deletions, and utilized try-with-resources internally for loadSchema and loadMainSchema inside SchemaFieldExtractor.java to close unused stream locks.

@github-actions
Copy link
Copy Markdown
Contributor

Hi there 👋 Thanks for your contribution!

The OpenMetadata team will review the PR shortly! Once it has been labeled as safe to test, the CI workflows
will start executing and we'll be able to make sure everything is working as expected.

Let us know if you need any help!

Comment on lines +194 to +199
} catch (IOException e) {
LOG.error("Error closing schema input stream '{}': {}", schemaPath, e.getMessage());
throw new SchemaProcessingException(
"Error loading schema '" + schemaPath + "': " + e.getMessage(),
"Error closing schema input stream: " + e.getMessage(),
SchemaProcessingException.ErrorType.INVALID_SCHEMA,
e);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Edge Case: IOException catch misleadingly says 'closing' but covers all IO

In both loadMainSchema (line 194) and loadSchema (line 454), the outer catch (IOException e) block logs "Error closing schema input stream" but this catch will also fire if an IOException is thrown during getResourceAsStream() or while reading the stream (e.g., inside JSONTokener). The log message and exception text are misleading — they suggest only a close failure, when the real cause could be a read error.

Consider using a more general message like "Error reading schema input stream" to accurately reflect all possible IOException origins within the try-with-resources block.

Suggested fix:

Change the log and exception messages from:
  "Error closing schema input stream ..."
to:
  "Error reading schema input stream ..."

Was this helpful? React with 👍 / 👎 | Reply gitar fix to apply this suggestion

@gitar-bot
Copy link
Copy Markdown

gitar-bot bot commented Apr 17, 2026

Code Review 👍 Approved with suggestions 0 resolved / 1 findings

Prevents resource leakage in SchemaFieldExtractor and suppresses unnecessary logging in FeedRepository. Refactor the misleading 'closing' log message in the IOException catch blocks to accurately reflect potential read or stream retrieval errors.

💡 Edge Case: IOException catch misleadingly says 'closing' but covers all IO

📄 openmetadata-service/src/main/java/org/openmetadata/service/util/SchemaFieldExtractor.java:194-199 📄 openmetadata-service/src/main/java/org/openmetadata/service/util/SchemaFieldExtractor.java:454-458

In both loadMainSchema (line 194) and loadSchema (line 454), the outer catch (IOException e) block logs "Error closing schema input stream" but this catch will also fire if an IOException is thrown during getResourceAsStream() or while reading the stream (e.g., inside JSONTokener). The log message and exception text are misleading — they suggest only a close failure, when the real cause could be a read error.

Consider using a more general message like "Error reading schema input stream" to accurately reflect all possible IOException origins within the try-with-resources block.

Suggested fix
Change the log and exception messages from:
  "Error closing schema input stream ..."
to:
  "Error reading schema input stream ..."
🤖 Prompt for agents
Code Review: Prevents resource leakage in SchemaFieldExtractor and suppresses unnecessary logging in FeedRepository. Refactor the misleading 'closing' log message in the IOException catch blocks to accurately reflect potential read or stream retrieval errors.

1. 💡 Edge Case: IOException catch misleadingly says 'closing' but covers all IO
   Files: openmetadata-service/src/main/java/org/openmetadata/service/util/SchemaFieldExtractor.java:194-199, openmetadata-service/src/main/java/org/openmetadata/service/util/SchemaFieldExtractor.java:454-458

   In both `loadMainSchema` (line 194) and `loadSchema` (line 454), the outer `catch (IOException e)` block logs "Error closing schema input stream" but this catch will also fire if an `IOException` is thrown during `getResourceAsStream()` or while reading the stream (e.g., inside `JSONTokener`). The log message and exception text are misleading — they suggest only a close failure, when the real cause could be a read error.
   
   Consider using a more general message like "Error reading schema input stream" to accurately reflect all possible `IOException` origins within the try-with-resources block.

   Suggested fix:
   Change the log and exception messages from:
     "Error closing schema input stream ..."
   to:
     "Error reading schema input stream ..."

Options

Display: compact → Showing less information.

Comment with these commands to change:

Compact
gitar display:verbose         

Was this helpful? React with 👍 / 👎 | Gitar

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR addresses backend debuggability and resource-handling issues by adding diagnostic logging during feed thread cleanup and ensuring schema resource streams are closed when loading JSON schemas.

Changes:

  • Add WARN logging when FeedRepository.deleteByAbout() fails to delete an individual thread.
  • Wrap schema resource InputStreams in try-with-resources in SchemaFieldExtractor to prevent resource leakage.
  • Add explicit handling for stream-close failures during schema loading.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.

File Description
openmetadata-service/src/main/java/org/openmetadata/service/util/SchemaFieldExtractor.java Uses try-with-resources for schema InputStreams and adds close-failure handling (but currently introduces compilation issues that must be fixed).
openmetadata-service/src/main/java/org/openmetadata/service/jdbi3/FeedRepository.java Logs thread deletion failures instead of silently swallowing exceptions.

Comment on lines +187 to +199
} catch (Exception e) {
LOG.error("Error loading schema '{}': {}", schemaPath, e.getMessage());
throw new SchemaProcessingException(
"Error loading schema '" + schemaPath + "': " + e.getMessage(),
SchemaProcessingException.ErrorType.INVALID_SCHEMA,
e);
}
} catch (IOException e) {
LOG.error("Error closing schema input stream '{}': {}", schemaPath, e.getMessage());
throw new SchemaProcessingException(
"Error loading schema '" + schemaPath + "': " + e.getMessage(),
"Error closing schema input stream: " + e.getMessage(),
SchemaProcessingException.ErrorType.INVALID_SCHEMA,
e);
Comment on lines 202 to 204
SchemaProcessingException.ErrorType.OTHER);
}
}
Comment on lines +448 to 458
} catch (Exception e) {
LOG.error("Error loading schema '{}': {}", schemaPath, e.getMessage());
throw new SchemaProcessingException(
"Error loading schema '" + schemaPath + "': " + e.getMessage(),
SchemaProcessingException.ErrorType.OTHER);
}
} catch (IOException e) {
LOG.error("Error closing schema input stream '{}': {}", schemaPath, e.getMessage());
throw new SchemaProcessingException(
"Error loading schema '" + schemaPath + "': " + e.getMessage(),
"Error closing schema input stream: " + e.getMessage(),
SchemaProcessingException.ErrorType.OTHER);
@aniruddhaadak80 aniruddhaadak80 changed the title Fix: Prevent resource leakage in SchemaFieldExtractor & silence in FeedRepository #27062 Fix: Prevent resource leakage in SchemaFieldExtractor and FeedRepository Apr 17, 2026
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.

2 participants