Skip to content

Commit

Permalink
Pluggable Monitors: Improved error logging / fixed resource leak in s…
Browse files Browse the repository at this point in the history
…ome rare conditions (#1638)

* Improve error logging for pluggable monitor

* Force quit of pluggable monitor if the port open fails
  • Loading branch information
cmaglie committed Jan 28, 2022
1 parent 14c98bb commit 1b0c127
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
2 changes: 1 addition & 1 deletion arduino/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ func (mon *PluggableMonitor) jsonDecodeLoop(in io.Reader, outChan chan<- *monito
if err := decoder.Decode(&msg); err != nil {
mon.incomingMessagesError = err
close(outChan)
mon.log.Errorf("stopped decode loop")
mon.log.Errorf("stopped decode loop: %s", err)
return
}
mon.log.
Expand Down
8 changes: 7 additions & 1 deletion commands/monitor/monitor.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/arduino/arduino-cli/i18n"
rpc "github.com/arduino/arduino-cli/rpc/cc/arduino/cli/commands/v1"
"github.com/arduino/go-properties-orderedmap"
"github.com/sirupsen/logrus"
)

var tr = i18n.Tr
Expand Down Expand Up @@ -76,18 +77,23 @@ func Monitor(ctx context.Context, req *rpc.MonitorRequest) (*PortProxy, *pluggab

descriptor, err := m.Describe()
if err != nil {
m.Quit()
return nil, nil, &arduino.FailedMonitorError{Cause: err}
}

monIO, err := m.Open(req.GetPort().GetAddress(), req.GetPort().GetProtocol())
if err != nil {
m.Quit()
return nil, nil, &arduino.FailedMonitorError{Cause: err}
}

for _, setting := range req.GetPortConfiguration().Settings {
m.Configure(setting.SettingId, setting.Value)
if err := m.Configure(setting.SettingId, setting.Value); err != nil {
logrus.Errorf("Could not set configuration %s=%s: %s", setting.SettingId, setting.Value, err)
}
}

logrus.Infof("Port %s successfully opened", req.GetPort().GetAddress())
return &PortProxy{
rw: monIO,
changeSettingsCB: m.Configure,
Expand Down

0 comments on commit 1b0c127

Please sign in to comment.