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

Disconnect broken #67

Closed
andig opened this issue Nov 29, 2024 · 1 comment · Fixed by #68
Closed

Disconnect broken #67

andig opened this issue Nov 29, 2024 · 1 comment · Fixed by #68

Comments

@andig
Copy link
Contributor

andig commented Nov 29, 2024

Refs evcc-io/evcc#17446 (comment)

In

// Disconnect the client
func (c *Client) Disconnect() error {
	c.isAuthenticated = false
	c.isConnected = false

        // -> THIS BLOCK CAN NEVER EXECUTE
	if c.isConnected && c.conn != nil {
		if err := c.conn.Close(); err != nil {
			return err
		}
	}

	Log.Info("disconnected")
	return nil
}
@andig
Copy link
Contributor Author

andig commented Nov 29, 2024

Instead of isConnected, wouldn't it be simpler to use c.conn == nil for this purpose? Disconnect would then become:

// Disconnect the client
func (c *Client) Disconnect() (err error) {
	c.isAuthenticated = false

	if c.conn != nil {
		err = c.conn.Close()
		c.conn = nil
		Log.Info("disconnected")
	}

	return err
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant