Skip to content

add changes to release resources when the channel becomes inactive#2241

Open
frankpuppa wants to merge 2 commits into
apache:developfrom
frankpuppa:2229-fix-thread-leak-reconnection
Open

add changes to release resources when the channel becomes inactive#2241
frankpuppa wants to merge 2 commits into
apache:developfrom
frankpuppa:2229-fix-thread-leak-reconnection

Conversation

@frankpuppa

Copy link
Copy Markdown

While I was looking into this issue I found out that there are two leaks. The first is related to the RequestTransactionManager and the other is from the NettyHashTimerTimeoutManager. As I was mentioning in the issue I opened last week, this leaks happens when the PLC goes offline and back online and the client tries to reconnecting to it in a cycle.

I was only able to test this on the modbus simulator which seems to work ok with the changes I made on this branch.
Please provide me a feedback or any consideration. I am attaching also a small video which shows that the resources are freed as expected.

Issue link

Screencast.2025-09-03.09.58.05.mp4

@sruehl sruehl requested a review from chrisdutz September 3, 2025 09:23
@chrisdutz

Copy link
Copy Markdown
Contributor

Hi Frank,
do I understand things correctly? The main difference is that you're overriding channelInactive in Plc4xNettyWrapper and forwarding that to the individual implementations?
Definitely looks sensible.

Chris

@chrisdutz

Copy link
Copy Markdown
Contributor

Could you please increase the log level for your additional log output to something "debug" or "trace"? "info" makes the drivers quite noisy.


@Override
public void channelInactive(ChannelHandlerContext ctx) throws Exception {
logger.info("channelInactive.. context: {}", ctx.name());

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.

Please set this to "debug" or "trace"


@Override
public void channelInactive(ConversationContext<Message> context) {
logger.info("On ChannelInactive");

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.

Please set this to "debug" or "trace"

@frankpuppa

Copy link
Copy Markdown
Author

Hi Frank, do I understand things correctly? The main difference is that you're overriding channelInactive in Plc4xNettyWrapper and forwarding that to the individual implementations? Definitely looks sensible.

Chris

Hello Chris,
Yes exactly, basically when the plc goes offline a channelInactive event is propagated. Within the nettywrapper I basically propagate the event in the implementations which can eventually shutdown the RequestTransactionManager and release the resources. I was able to test the functionality only for the ModbusTcpProtocol. I will fix the verbosity asap.

spnettec added a commit to spnettec/plc4x that referenced this pull request May 31, 2026
…lc4x

- fix(s7): S7HMuxImpl direct buffer leak per-message (PR apache#2542)
- fix(s7): alarm-query directBuffer not released in S7ProtocolLogic and S7NonHProtocolLogic (PR apache#2543)
- fix(s7,spi): decodeLargeReadResponse heap buffer not released in S7ProtocolLogic and S7NonHProtocolLogic
- feat(spi): SharedExecutor — JVM-scoped thread pools replace per-connection ThreadPoolExecutors to prevent thread accumulation on reconnect (PR apache#2281)
- fix(spi): RequestTransactionManager.shutdown() cancels in-flight requests without shutting down shared executor
- feat(spi): channelInactive lifecycle hook on Plc4xProtocolBase and Plc4xNettyWrapper; all drivers release resources on TCP disconnect (PR apache#2241)
- fix(eip): NPE in decodeSingleReadResponse when PLC returns error status and getData() is null (PR apache#2471)
- fix(umas): align pom version to 0.14.0.B-SNAPSHOT and fix RequestTransactionManager constructor call

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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