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

websocket connection is not properly stopped when the websocket is not connected #416

Closed
maaikez opened this issue Jan 25, 2024 · 0 comments · Fixed by #418
Closed

websocket connection is not properly stopped when the websocket is not connected #416

maaikez opened this issue Jan 25, 2024 · 0 comments · Fixed by #418
Assignees
Labels
bug Something isn't working OCPP2.0.1
Milestone

Comments

@maaikez
Copy link
Contributor

maaikez commented Jan 25, 2024

In

void ChargePoint::disconnect_websocket(websocketpp::close::status::value code) {    if (this->websocket != nullptr) {
        if (this->websocket->is_connected()) {
            this->disable_automatic_websocket_reconnects = true;
            this->websocket->disconnect(code);
        }
    }
}

The websocket is only disconnected when it is connected. That seems logical, but in the websocket->disconnect() function, things are done that also should be done when the websocket is not connected:

void WebsocketBase::disconnect(websocketpp::close::status::value code) {
    if (!this->initialized()) {
        EVLOG_error << "Cannot disconnect a websocket that was not initialized";
        return;
    }
    if (code == websocketpp::close::status::normal) {
        this->shutting_down = true;
    }

    {
        std::lock_guard<std::mutex> lk(this->reconnect_mutex);
        if (this->reconnect_timer) {
            this->reconnect_timer.get()->cancel();
        }
    }

    if (this->ping_timer) {
        this->ping_timer->stop();
    }

    EVLOG_info << "Disconnecting websocket...";
    this->close(code, "");
}

Setting the shutting_down flag and cancel the reconnect_timer should also be done when the websocket is not connected.

@maaikez maaikez self-assigned this Jan 25, 2024
@maaikez maaikez added bug Something isn't working OCPP2.0.1 labels Jan 25, 2024
@maaikez maaikez added this to the 1.0 release milestone Jan 25, 2024
@maaikez maaikez linked a pull request Jan 25, 2024 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working OCPP2.0.1
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant