Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot stop client if no connection established #337

Closed
joristork opened this issue Nov 18, 2020 · 8 comments · May be fixed by #533
Closed

cannot stop client if no connection established #337

joristork opened this issue Nov 18, 2020 · 8 comments · May be fixed by #533
Labels
bug Something isn't working

Comments

@joristork
Copy link

Steps to reproduce:

  1. Ensure that the client is not able to connect to the given opc-ua server URI
  2. client.connect()
  3. client.disconnect()

The client will raise an AttributeError.
If one catches this, the asyncua thread hangs.

@swamper123 swamper123 added the bug Something isn't working label Nov 18, 2020
@swamper123 swamper123 changed the title Bug: cannot stop client if no connection established cannot stop client if no connection established Nov 18, 2020
@swamper123
Copy link
Contributor

So the first connect request isn't successfull or is still running (from your step1)?
And then you are start another connect request?

Can you provide a small example code (eventually commented)? That would clear some questions and missunderstandings.

@AndreasHeine
Copy link
Member

if you have questions use the discussions feature of this repo (your post is not related to the topic...) if you open a new discussion please provide consoleoutput and stacktrace, just posting your code is not enough

@JuBanaSh
Copy link

@AndreasHeine Sorry, I will correct it.

@dan-sel
Copy link

dan-sel commented Feb 18, 2021

@joristork The asyncua thread doesn't hang, it was never told to stop. The exception is raised in the self.tloop.post(self.aio_obj.disconnect()) call in asyncua.sync.Client.disconnect. This means that the code that stops the thread loop is never called. Quick fix: manage the thread loop yourself.

@Randelung
Copy link
Contributor

Pretty sure it's just a case of 'forgot to check if the task exists that I'm trying to cancel'. My PR allowed me to gracefully close the clients without first establishing a connection.

@joristork
Copy link
Author

Thank you @dan-sel and @Randelung , I will test your suggestions and feed back.

@joristork
Copy link
Author

I solved / worked around this by simply checking that my client is connected before calling the disconnect() method.

@joristork
Copy link
Author

joristork commented Jul 7, 2021

My criterion for checking it is connected:

if (                                                                                                                                                                                           
    hasattr(self._client, "uaclient")                                                                                                                                                          
    and hasattr(self._client.uaclient, "protocol")                                                                                                                                             
    and self._client.uaclient.protocol                                                                                                                                                         
    and (self._client.uaclient.protocol.state == UASocketProtocol.OPEN)                                                                                                                      
):

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants