eModbus / eModbus

Modbus library for RTU, ASCII and TCP protocols. Primarily developed on and for ESP32 MCUs.

Home Page:https://emodbus.github.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ModbusServerTCPasync crash calling stop() if server it's not running, please add a check

dsilletti opened this issue · comments

Describe the bug
stopping the server with MBserver.stop() cause crash if the server is not running.

Please add a check to be sure the server is running before trying to stop it.
I fixed by myself adding this in the file ModbusServerTCPasync.cpp:

bool ModbusServerTCPasync::stop() {

  // required check!!!
  if (!server) {
    LOG_W("Server not running.\n");
    return false;
  }
  
  // stop server to prevent new clients connecting
  server->end();
......

Expected behavior
stop() should return false if server it's not running and not crash.

To Reproduce
Steps to reproduce the behavior:
stop the server when it's not running using the MBserver.stop() function

created PR #246 to fix the issue

@bertmelis currently is reworking the async code anyway, so he will take care of this.

Thanks for the find.