From 00cc8bce89bbbe272e7c0d7ef13b49aa6ff51c39 Mon Sep 17 00:00:00 2001 From: evilsocket Date: Sun, 11 Feb 2018 19:29:05 +0100 Subject: [PATCH] fix: adding a 10 seconds max timeout to modules stop callbacks. --- session/module.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/session/module.go b/session/module.go index 2b656744..19820838 100644 --- a/session/module.go +++ b/session/module.go @@ -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) + } } }