Skip to content

Commit

Permalink
agent/dispatcher: Close websocket if NewDispatcher fails (#511)
Browse files Browse the repository at this point in the history
Maybe the cause of memory leaks? And maybe also the cause of the issues
where the vm-monitor times out trying to read the version information
off the protocol.
  • Loading branch information
sharnoff authored Aug 31, 2023
1 parent 955a627 commit 80b291c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/agent/dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,14 @@ func NewDispatcher(
return nil, fmt.Errorf("error establishing websocket connection to %s: %w", addr, err)
}

// If we return early, make sure we close the websocket
connectionOk := false
defer func() {
if !connectionOk {
c.Close(websocket.StatusInternalError, "could not establish protocol")
}
}()

versionRange := api.VersionRange[api.MonitorProtoVersion]{
Min: MinMonitorProtocolVersion,
Max: MaxMonitorProtocolVersion,
Expand Down Expand Up @@ -132,6 +140,7 @@ func NewDispatcher(
server: parent,
lock: sync.Mutex{},
}
connectionOk = true
return disp, nil
}

Expand Down

0 comments on commit 80b291c

Please sign in to comment.