Skip to content

Commit 7e472a8

Browse files
committed
Added a small delay after monitor closing
This is a countermeasure for kernel/firwmare bugs: resources may take a few milliseconds to actually get freed for real after killing the process, or even after a regular closing. This delay makes the caller more resilient to this kind of issues.
1 parent 813cfe7 commit 7e472a8

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

Diff for: arduino/monitor/monitor.go

+9-1
Original file line numberDiff line numberDiff line change
@@ -298,7 +298,15 @@ func (mon *PluggableMonitor) Close() error {
298298

299299
// Quit terminates the monitor. No more commands can be accepted by the monitor.
300300
func (mon *PluggableMonitor) Quit() error {
301-
defer mon.killProcess() // ensure that killProcess is called in any case...
301+
defer func() {
302+
mon.killProcess() // ensure that killProcess is called in any case...
303+
304+
// This is a countermeasure for kernel/firwmare bugs:
305+
// resources may take a few milliseconds to actually get freed for real
306+
// after killing the process, or even after a regular closing.
307+
// This delay makes the caller more resilient to this kind of issues.
308+
time.Sleep(500 * time.Millisecond)
309+
}()
302310

303311
if err := mon.sendCommand("QUIT\n"); err != nil {
304312
return err

0 commit comments

Comments
 (0)