Skip to content

[Enhancement] Fix potential resource leak #9447

Open
@xcx1r3

Description

@xcx1r3

Before Creating the Enhancement Request

  • I have confirmed that this should be classified as an enhancement rather than a bug/feature.

Summary

leak 1

org.apache.rocketmq.container.BrokerContainerStartup#loadConfig InputStream in.

Image

If an exception occurs during properties.load(in), the in.close() line will be skipped, and the InputStream will not be closed.

leak 2

org.apache.rocketmq.test.schema.SchemaTools#load BufferedReader br.

Image

The line br.close(); is intended to release this resource. However, it might be skipped if an exception occurs within the while loop.

leak 3

org.apache.rocketmq.remoting.protocol.body.RegisterBrokerBody#decode InflaterInputStream inflaterInputStream

inflaterInputStream is never closed.

leak 4

org.apache.rocketmq.remoting.protocol.body.RegisterBrokerBody#encode DeflaterOutputStream outputStream
outputStream is never closed.

leak 5

org.apache.rocketmq.test.util.DuplicateMessageInfo#checkDuplicatedMessageInfo OutputStream out

Image

The code attempts to close the stream with out.close();. However, if an exception occurs after the FileOutputStream is successfully opened but before out.close() is executed, the close() call will be skipped.

leak 6

org.apache.rocketmq.broker.BrokerStartup#loadConfig InputStream in

Image
same as leak 1

Motivation

This enhancement effort revealed potential resource leaks. Recurrent leakage would cause an aggregation of unreleased resources, ultimately leading to the depletion of system resources available to the application.

Describe the Solution You'd Like

try-with-resources solutions effectively address the resource leak.

Describe Alternatives You've Considered

Proposed solution is widely recognized as the most effective and appropriate method.

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions