Skip to content

Master, heap corruption with broadacst requests to responsive slaves (EPROT-69) #174

Description

@Wittronics-Wisse

Checklist

  • Checked the issue tracker for similar issues to ensure this is not a duplicate
  • Read the documentation to confirm the issue is not addressed there and your configuration is set correctly
  • Tested with the latest version to ensure the issue hasn't been fixed

How often does this bug occurs?

rarely

Expected behavior

Continuous RTU Modbus communication.

Actual behavior (suspected bug)

After a time (observed between 12-36 hours) of continuous reading & writing to Modbus slaves, the heap is overwritten and results in a reset.

Error logs or terminal output

Char #116 before the crash is read 0x0002 . Char #21 is a broadcast.

I (30303956) MODBUS: Read param CID 124
I (30303976) MODBUS: Characteristic #124  () value = (0x004c) parameter read successful.
I (30303976) MODBUS: Read done param CID 124
I (30303993) MODBUS: Read param CID 120
I (30304011) MODBUS: Characteristic #120  () value = (0x002a) parameter read successful.
I (30304012) MODBUS: Read done param CID 120
I (30304038) MODBUS: Read param CID 27
I (30304056) MODBUS: Characteristic #27  () value = (0x8000) parameter read successful.
I (30304057) MODBUS: Read done param CID 27
I (30304073) MODBUS: Read param CID 116
I (30304091) MODBUS: Characteristic #116  () value = (0x0002) parameter read successful.
I (30304092) MODBUS: Read done param CID 116
I (30304108) MODBUS: Read param CID 121
I (30304126) MODBUS: Characteristic #121  () value = (0x0000) parameter read successful.
I (30304126) MODBUS: Read done param CID 121
I (30304153) MODBUS: Read param CID 27
I (30304172) MODBUS: Characteristic #27  () value = (0x8000) parameter read successful.
I (30304172) MODBUS: Read done param CID 27
I (30304189) MODBUS: Write param CID 21
E (30307203) MB_CONTROLLER_MASTER: mbc_master_set_parameter(93): Master set parameter failure, error=(0x107) (ESP_ERR_TIMEOUT).
E (30307204) MODBUS: Characteristic #21 () write fail, err = 0x107 (ESP_ERR_TIMEOUT).
E (30310213) MB_CONTROLLER_MASTER: mbc_master_set_parameter(93): Master set parameter failure, error=(0x103) (ESP_ERR_INVALID_STATE).
E (30310215) MODBUS: Characteristic #21 () write fail, err = 0x103 (ESP_ERR_INVALID_STATE).
I (30313150) MODBUS: Characteristic #21  () value = (0x07df), write successful.
I (30313151) MODBUS: Write done param CID 21
I (30313167) MODBUS: Read param CID 116
E (30313190) MB_CONTROLLER_MASTER: mbc_master_get_parameter(131): Master get parameter failure, error=(0x108) (ESP_ERR_INVALID_RESPONSE).
E (30313192) MODBUS: Characteristic #116  (), read parameter read fail.
I (30313199) MODBUS: Read done param CID 116
CORRUPT HEAP: Invalid data at 0x3ffd2168. Expected 0xfefefefe got 0xfefe0002
I (30313220) MODBUS: Read param CID 121
CORRUPT HEAP: Invalid data at 0x3ffd2168. Expected 0xfefefefe got 0xfefe0002
CORRUPT HEAP: Invalid data at 0x3ffd2168. Expected 0xfe got 0x02
CORRUPT HEAP: Invalid data at 0x3ffd2168. Expected 0xfe got 0x02

And

Second log prints CID information on failed Modbus transactions.

E (117981772) MB_CONTROLLER_MASTER: mbc_master_set_parameter(93): Master set parameter failure, error=(0x107) (ESP_ERR_TIMEOUT).
E (117981774) MODBUS: Write FAIL: Char #21, err = 0x107 (ESP_ERR_TIMEOUT) Try:1
  Slave: 0, RegStart: 0C00, MBParamType: 0, RegSize: 16, ParamSize: 32, ParamOffset: 0, ParamType: 7
E (117983289) MB_CONTROLLER_MASTER: mbc_master_get_parameter(131): Master get parameter failure, error=(0x108) (ESP_ERR_INVALID_RESPONSE).
E (117983292) MODBUS: Read FAIL: Char #116, err = 0x108 (ESP_ERR_INVALID_RESPONSE)
  Slave: 32, RegStart: 0800, MBParamType: 1, RegSize: 1, ParamSize: 2, ParamOffset: 0, ParamType: 1
CORRUPT HEAP: Invalid data at 0x3ffccff0. Expected 0xfefefefe got 0xfefe0002
E (117983325) MODBUS: HEAP corrupt after Read param CID 116
CORRUPT HEAP: Invalid data at 0x3ffccff0. Expected 0xfefefefe got 0xfefe0002
E (117983339) MODBUS: HEAP corrupt before Read param CID 121
CORRUPT HEAP: Invalid data at 0x3ffccff0. Expected 0xfe got 0x02
CORRUPT HEAP: Invalid data at 0x3ffccff0. Expected 0xfe got 0x02

Steps to reproduce the behavior

We have a responsive system, usually a response start between 0-10mS after slave receive.
Baudrate: 230400

To improve response we changed a few lines in the component:
mb_config.h
line:166 Changed so broadcasts can be send more often
#define MB_MASTER_DELAY_MS_CONVERT 20

port_serial.c
line 19: Changed to 1.75mS because 3.5T is too short
#define MB_SERIAL_TOUT (36)

line 159: Removed semaphore for fast systems
// If bus is busy or fragmented data is received, then flush buffer
// if (mb_port_ser_bus_sema_is_busy(&port_obj->base) && port_obj->base.descr.is_master) {
// mb_port_ser_rx_flush(&port_obj->base);
// break;
// }

line 90: Removed unused function after removing semaphore
// static bool mb_port_ser_bus_sema_is_busy(mb_port_base_t *inst)

Communication is continuous. Reading every 50mS, Writing every 5000mS. Most of them are broadcasts.
Time to reproduce is unclear, lays between 12 to 36 hours on most systems.

Project release version

2.1.1

System architecture

Intel/AMD 64-bit (modern PC, older Mac)

Operating system

Windows

Operating system version

Windows 11

Shell

CMD

Additional context

I've also experienced problems with flash actions when a timer_delete is called through the Modbus component while NVS is active. I currently do not have that log, but will save it when it happens again.
UART ISR is set in IRAM.

Metadata

Metadata

Assignees

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions