ros / ros_comm

ROS communications-related packages, including core client libraries (roscpp, rospy, roslisp) and graph introspection tools (rostopic, rosnode, rosservice, rosparam).
http://wiki.ros.org/ros_comm
745 stars 911 forks source link

RospyLogger stuck in indefinte loop #2352

Open StephanOLC opened 9 months ago

StephanOLC commented 9 months ago

By importing rosbag the standard logger is overwritte. When sending a warning or error the logger is stuck in an indefinte loop. This can cause other python libraries to malfunction (for example Flask). To reproduce

import rosbag
import logging

logger = logging.getLogger('myLogger') # gets a RospyLogger object
logger.warn('message') # gets stuck in infinite loop

Infinite Loop is inside def findCaller(self, *args, **kwargs): in roslogging.py.

Cause of the issue is:

file_name, lineno, func_name = super(RospyLogger, self).findCaller(*args, **kwargs)[:3] # returns file_name = ".../rosgraph/roslogging.py" lineno = 57  call func_name = 'findCaller'

returns itself as the caller:

Afterwards it tries to find a matching stackframe (skipping the first), but there is none. The loop to do so is a while loop, but the condition does not change, as f is not reassigned if the last frame is reached.

while hasattr(f, "f_code"):
            # Search for the right frame using the data already found by parent class.
            co = f.f_code
            filename = os.path.normcase(co.co_filename)
            if filename == file_name and f.f_lineno == lineno and co.co_name == func_name:
                break
            if f.f_back:
                f = f.f_back

There are two things to fix:

Alternativly do not set the global Logging class to RaspyLogger.