locka99 / opcua

A client and server implementation of the OPC UA specification written in Rust
Mozilla Public License 2.0
476 stars 129 forks source link

Client with 100% CPU usage #195

Open ctron opened 2 years ago

ctron commented 2 years ago

Having a simple client example, subscribing to a single item, I have a CPU usage of 100%.

Maybe I am doing something wrong, or is that expected? I am mainly using the code of simple-client.

ctron commented 2 years ago

I dug a bit into this, and couldn't find any difference to the simple-client example, which did work just fine.

I then ran an update on all dependencies (cargo update), and the problem was gone. The lock file had some old dependencies, which seem to have causes this.

:shrug: … sorry for the noise.

ctron commented 2 years ago

So I did run into this again, even with newer dependencies. I dug a bit deeper, and noticed that it is repeatedly returning "none" in the following code:

https://github.com/locka99/opcua/blob/3b052d0f8a7c5fcb99f164ebb31c22d61c8a1d2d/lib/src/server/comms/tcp_transport.rs#L451-L453

Do my understanding, "none" would mean that the socket got closed. So I guess that should be treated as such, and shutdown reader and writer.

ctron commented 2 years ago

So it looks like that this comes from a previous session, when connecting using connect_to_endpoint, where is does retrieve the remote endpoints. The connection gets closed, but the reader loop never gets cleaned up, endlessly polling the closed socket.

Adding a break to the situation, shutting down the writer in the process, seems to fix this issue.

@svanharmelen You might want to watch out for this too.

svanharmelen commented 2 years ago

Thanks for the ping!

lovasoa commented 2 years ago

This should be fixed in my pr : https://github.com/locka99/opcua/pull/201

@ctron : could you test it ?

You can specify in your dependencies

opcua = { git = "https://github.com/lovasoa/opcua", branch = "fix-zombie-tasks" }
ctron commented 2 years ago

@lovasoa Sure, I will give it a try. I might however do this next Monday.