mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -07:00
fix: adding a 10 seconds max timeout to modules stop callbacks.
This commit is contained in:
parent
e7ecd1133d
commit
00cc8bce89
1 changed files with 14 additions and 2 deletions
|
@ -4,6 +4,7 @@ import (
|
|||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/evilsocket/bettercap-ng/core"
|
||||
)
|
||||
|
@ -148,8 +149,19 @@ func (m *SessionModule) SetRunning(running bool, cb func()) error {
|
|||
// this is the worker, start async
|
||||
go cb()
|
||||
} else {
|
||||
// stop callback, this is sync
|
||||
cb()
|
||||
// stop callback, this is sync with a 10 seconds timeout
|
||||
done := make(chan bool, 1)
|
||||
go func() {
|
||||
cb()
|
||||
done <- true
|
||||
}()
|
||||
|
||||
select {
|
||||
case _ = <-done:
|
||||
return nil
|
||||
case <-time.After(10 * time.Second):
|
||||
fmt.Printf("%s: Stopping module %s timed out.", core.Yellow(core.Bold("WARNING")), m.Name)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue