apache / plc4x

PLC4X The Industrial IoT adapter
https://plc4x.apache.org/
Apache License 2.0
1.26k stars 401 forks source link

[Bug]: S7 driver - java.lang.OutOfMemoryError: unable to create native thread #801

Closed DmitriiMukhin closed 1 year ago

DmitriiMukhin commented 1 year ago

What happened?

When s7 driver can't establish connection with controller it creates threads that being falling into park state TIMED_WAITING. While application keep trying to connect via PlcDriverManger.getConnection(url) such threads count continuously growing. In the end we have java.lang.OutOfMemoryError: unable to create native thread.

We are using s7 driver to communicate with different controllers from single app.

Screenshots just to demonstrate an issue. Driver creates thousands of such threads.

Screenshot from 2023-02-13 16-06-18 Screenshot from 2023-02-13 16-06-30 Screenshot from 2023-02-13 16-06-39 Screenshot from 2023-02-13 16-10-05 Screenshot from 2023-02-13 16-10-44

Version

v0.10.0

Programming Languages

Protocols

heyoulin commented 1 year ago

Can you try my resp https://github.com/spnettec/plc4x.git? heyoulin branch. If no problem i will cretae a pull request.

image
DmitriiMukhin commented 1 year ago

@heyoulin Thank you - great job. I think this part of your solution helped me.

                pipeline.addLast(new ChannelInboundHandlerAdapter() {
                                     @Override
                                     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
                                             throws PlcConnectionException {
                                         logger.error("unknown error, close the connection", cause);
                                         close();
                                     }
                                 }
                );

I've tested for a while - at first glance it works. Abandoned(parked) threads are absent. Connection is establishing as it should in normal situation, I mean when controller is accessible. I'll continue testing.

I'll be forced to fork 0.10.0 release to our company repo with such fix. As we don't know when new fixed release will be published.

DmitriiMukhin commented 1 year ago

@heyoulin Thank you - great job. I think this part of your solution helped me.

                pipeline.addLast(new ChannelInboundHandlerAdapter() {
                                     @Override
                                     public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause)
                                             throws PlcConnectionException {
                                         logger.error("unknown error, close the connection", cause);
                                         close();
                                     }
                                 }
                );

I've tested for a while - at first glance it works. Abandoned(parked) threads are absent. Connection is establishing as it should in normal situation, I mean when controller is accessible. I'll continue testing.

I'll be forced to fork 0.10.0 release to our company repo with such fix. As we don't know when new fixed release will be published.

I was wrong. All code changes are needed.

chrisdutz commented 1 year ago

Is this issue still open or has it been fixed?

DmitriiMukhin commented 1 year ago

Is this issue still open or has it been fixed?

It could be fixed with provided PR. Such fix was tested in our local company fork. No more issues.

chrisdutz commented 1 year ago

Ok ... as I've merged that PR, I'll close this issue, right?