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

AttributeError: 'NoneType' object has no attribute 'close' #2212

Closed
MatthijsBurgh opened this issue Dec 21, 2021 · 8 comments
Closed

AttributeError: 'NoneType' object has no attribute 'close' #2212

MatthijsBurgh opened this issue Dec 21, 2021 · 8 comments

Comments

@MatthijsBurgh
Copy link

I have no clue of the following exception is caused by incorrect implemetnation on my side or caused by a bug in rospy.

Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_pubsub.py", line 185, in robust_connect_subscriber
    conn.receive_loop(receive_cb)	    
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 846, in receive_loop
    self.close()
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 858, in close
    self.socket.close()
AttributeError: 'NoneType' object has no attribute 'close'
@MatthijsBurgh
Copy link
Author

@jacobperron friendly ping

@jacobperron
Copy link
Contributor

The error message makes it sound like it's a bug in rospy.

@MatthijsBurgh Can you provide simple steps to reproduce the error?

@MatthijsBurgh
Copy link
Author

MatthijsBurgh commented Jan 20, 2022

@jacobperron I will get back to you when I have been able to isolate the issue into a reproducible error.

The situation in which I experienced this error the first time, was in a node launching other nodes.

Now I also experience this in nodes with an action_server simple_client. In both situations it happens during stopping of a node.

Exception in thread /hero/local_planner/action_server/result:
Traceback (most recent call last):
  File "/usr/lib/python3.8/threading.py", line 932, in _bootstrap_inner
    self.run()
  File "/usr/lib/python3.8/threading.py", line 870, in run
    self._target(*self._args, **self._kwargs)
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_pubsub.py", line 185, in robust_connect_subscriber
    conn.receive_loop(receive_cb)	    
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 846, in receive_loop
    self.close()
  File "/opt/ros/noetic/lib/python3/dist-packages/rospy/impl/tcpros_base.py", line 858, in close
    self.socket.close()
AttributeError: 'NoneType' object has no attribute 'close'

@MichaelGrupp
Copy link
Contributor

MichaelGrupp commented Feb 1, 2022

This is most likely a race condition due to a previous self.close() where the socket is set to None here. Given the various places where self.close() is called in TCPROSTransport because of errors (like maybe (improper) shutdown in your case) without proper thread sync, I wouldn't be surprised if it crashes sometimes.

We also experienced different cases where either the socket or the buffers were called as None, and after going through the code I think this can only be stabilized by refactoring the code to be more thread safe.

@madmage
Copy link
Contributor

madmage commented Mar 15, 2022

The complete solution of this issue would require to rewrite the classes to be thread safe. Anyway, a opened a PR with a workaround here: #2233

@MatthijsBurgh
Copy link
Author

@jacobperron What do you think about #2233? Or would like to go for some locks?

jacobperron pushed a commit that referenced this issue May 31, 2022
#2233)

Co-authored-by: Daniele Calisi <calisi@magazino.eu>
@jacobperron
Copy link
Contributor

I've merged the workaround. Thanks @madmage!

@lyh458
Copy link

lyh458 commented Jul 13, 2022

Hi there,
The same error raised when I use a simple function rospy.wait_for_message. I called this function in a sub-thread when I met this error first time, I thought it's the multi-thread caused. Then I made a simple test (single nodes without multi-thread), but same error raised. Here is the test code:

import rospy
from sensor_msgs.msg import JointState

import rospy
from sensor_msgs.msg import JointState

def main():
    rospy.init_node('test', anonymous=True)
    while not rospy.is_shutdown():
        js = rospy.wait_for_message('/iiwa/joint_states', JointState, timeout=5)
        print(list(js.position))

if __name__ == '__main__':
    main()

As the workaround in #2233 , a multi-thread set needed, but how can do it in single node and single thread case?

Thanks in advance!

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

No branches or pull requests

5 participants