FreeOpcUa / freeopcua

Open Source C++ OPC-UA Server and Client Library
http://freeopcua.github.io/
GNU Lesser General Public License v3.0
712 stars 342 forks source link

Problem closing the connection to OPC UA server #106

Open art-rasa opened 9 years ago

art-rasa commented 9 years ago

Hello,

I am a newbie programmer making a Python program with FreeOpcUa. I would like to periodically read the values of some variables from a PLC device.

I have set up a data_log() function which reads the values of some data variables from a UA server one by one and stores them to a database or text file. I would like to call this function periodically. However, when the data_log() function is finished executing and is closing the connection, the program exits with an exit status 134. At the end of the function execution I get this message:

CloseSession response is 
terminate called without an active exception
Aborted

------------------
(program exited with code: 134)
Press return to continue

The example client in "python/examples/" does not have this problem. The example client always exits cleanly with exit status 0. I would appreciate some advice on how to avoid this problem.

Full console output: http://pastebin.com/u3wNeV28 Main program file: http://pastebin.com/f5RRz6rW

oroulet commented 9 years ago

Hi, I have seen this before, it seems to happen randomly on my pc and that you found a way to get this every time. your code uses too many internal things I do not know of. Could you try to run your program with gdb --args python yourprgram.py then write run wait for crash .................. info thread where

and send me the output.

If you manage to You could also try to create a small selv contained python program I can also try to run it on my pc. But I do not have this plc.

art-rasa commented 9 years ago

Hello oroulet,

thanks for your advice. I will try using gdb as you instructed when I return to my school computer.

I managed to solve this problem simply by calling time.sleep(15) before calling client.disconnect(). Now I can use "apscheduler" to schedule the data reading from the PLC.

destogl commented 9 years ago

Hello,

I also get similar error, but with C++ api. Error is:

Receive ServiceFault from Server with StatusCode The session was closed by the client. (0x80260000)

expecting 4  received: 0
Not enough data was received from channel.
Error received empty packet form server
expecting 1  received: 0

Error happens after I try to close connection and my application had subscription to a variable. Currently I am only unsubscribing (not deleting subscribers because get the same error).

Maybe this helps to get a clue...

RavilN commented 9 years ago

This problem might be solved by the changes in the pull request I created recently. In example client I had problems related to close session, and did some changes trying to resolve it.

destogl commented 9 years ago

Seams to work now perfectly!! Thank you!

From my side can be closed.

oroulet commented 9 years ago

that sounds a bit strange, I do not see any change that could influence that... I think we will wait a while before closing