Skip to content

Commit

Permalink
Merge pull request #12 from matc17/main
Browse files Browse the repository at this point in the history
All Programs now running since >4 weeks without issues..
  • Loading branch information
mlnoga authored Apr 21, 2024
2 parents 03eacb9 + 872bcaa commit 744e0ab
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ var connectionCache map[string]*Connection = make(map[string]*Connection)
// Creates a new connection to a RCT device at the given address
func NewConnection(host string, cache time.Duration) (*Connection, error) {
if conn, ok := connectionCache[host]; ok {
return conn, nil
if conn.conn != nil { // there might be dead connection in the cache, e.g. when connection was disconnected
return conn, nil
}
}

conn := &Connection{
Expand Down Expand Up @@ -53,6 +55,7 @@ func (c *Connection) connect() (err error) {
func (c *Connection) Close() {
c.conn.Close()
c.conn = nil
delete(connectionCache, c.host) // connection is dead, no need to cache any more
}

// Sends the given RCT datagram via the connection
Expand Down

0 comments on commit 744e0ab

Please sign in to comment.