Skip to content

Crash when editing device dataitem in DeviceModel #423

Description

@mnoomnoo

Changing the dataitem ID in Device.XML while the agent is running will sometimes cause a crash. To simulate changing the ID of the dataitem in dummyAdapter_42 I used the following python script

import xml.etree.ElementTree as ET
import time

device_xml = 'C:/PROGRAMS/cppagent-2.2/bin/Devices.xml'
id_counter = 0

def write_device_xml_updates():
	global counter
	global id_counter

	tree:ET.ElementTree = ET.ElementTree()
	root:ET.Element = ET.Element("")
	with open(device_xml, "rb") as f:
		tree = ET.parse(f)
		root = tree.getroot()

	device = root.findall('*/Device')[0]

	items = device.findall(".//*[@id]")
	for item in items:
		item.attrib["id"] = f"newEleID{id_counter}"
		id_counter += 1

	with open(device_xml, "wb") as f:
		tree.write(f)

while True:

	write_device_xml_updates()

	time.sleep(25)

Here is the Devices.XML I used:

<MTConnectDevices>
	<Devices>

		<Device uuid="dummyAdapter_42" id="dummyAdapter_42" name="dummyAdapter">
			<Components>
				<Controller id="dummyCtl">
					<DataItems>
						<DataItem id="msgTest" type="MESSAGE" category= "EVENT"></DataItem>
					</DataItems>
				</Controller>				
			</Components>
		</Device>

	</Devices>
</MTConnectDevices>

Here is my agent.cfg:

Devices = Devices.xml
AllowPut = true
ReconnectInterval = 1000
BufferSize = 17
SchemaVersion = 2.0
MonitorConfigFiles = true

Adapters {

  dummyAdapter {
      Host = 127.0.0.1
      Port = 7790
   }   
}

Files {
    schemas {
        Path = ../schemas
        Location = /schemas/
    }
    styles {
        Path = ../styles
        Location = /styles/
    }
    Favicon {
        Path = ../styles/favicon.ico
        Location = /favicon.ico
    }
}

# StreamsStyle { Location = /styles/Streams.xsl }
DevicesStyle { Location = /styles/styles.xsl }
StreamsStyle { Location = /styles/styles.xsl }

# Logger Configuration
logger_config
{
    logging_level = debug
}

Every 25 seconds the python script will update the Devices.XML and let the agent attempt to update the device model.
The crash occurs in the function void Observation::updateDataItem(std::unordered_map<std::string, WeakDataItemPtr> &diMap) due to m_dataItem.lock() returning an empty shared pointer (DataItemPtr).
Inside CircularBuffer::updateDataItems() when iterating over m_slidingBuffer, if the current Observation is an orphan, inside of o->updateDataItem(diMap); will crash when attempting to use the result of m_dataItem.lock(); as a parameter to diMap.find()

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions