Skip to content

Commit 744e0ab

Browse files
authored
Merge pull request #12 from matc17/main
All Programs now running since >4 weeks without issues..
2 parents 03eacb9 + 872bcaa commit 744e0ab

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

connection.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,9 @@ var connectionCache map[string]*Connection = make(map[string]*Connection)
2424
// Creates a new connection to a RCT device at the given address
2525
func NewConnection(host string, cache time.Duration) (*Connection, error) {
2626
if conn, ok := connectionCache[host]; ok {
27-
return conn, nil
27+
if conn.conn != nil { // there might be dead connection in the cache, e.g. when connection was disconnected
28+
return conn, nil
29+
}
2830
}
2931

3032
conn := &Connection{
@@ -53,6 +55,7 @@ func (c *Connection) connect() (err error) {
5355
func (c *Connection) Close() {
5456
c.conn.Close()
5557
c.conn = nil
58+
delete(connectionCache, c.host) // connection is dead, no need to cache any more
5659
}
5760

5861
// Sends the given RCT datagram via the connection

0 commit comments

Comments
 (0)