|
@@ -248,15 +248,15 @@ func main() {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- err = worker.Init(config)
|
|
|
|
|
|
|
+ workCtx, stopWork := context.WithCancel(context.Background())
|
|
|
|
|
+ defer stopWork()
|
|
|
|
|
+
|
|
|
|
|
+ err = worker.Init(workCtx, config)
|
|
|
if err != nil {
|
|
if err != nil {
|
|
|
psiphon.NoticeError("error in init: %s", err)
|
|
psiphon.NoticeError("error in init: %s", err)
|
|
|
os.Exit(1)
|
|
os.Exit(1)
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- workCtx, stopWork := context.WithCancel(context.Background())
|
|
|
|
|
- defer stopWork()
|
|
|
|
|
-
|
|
|
|
|
workWaitGroup := new(sync.WaitGroup)
|
|
workWaitGroup := new(sync.WaitGroup)
|
|
|
workWaitGroup.Add(1)
|
|
workWaitGroup.Add(1)
|
|
|
go func() {
|
|
go func() {
|
|
@@ -352,7 +352,7 @@ func (p *tunProvider) GetSecondaryDnsServer() string {
|
|
|
// compiled executable.
|
|
// compiled executable.
|
|
|
type Worker interface {
|
|
type Worker interface {
|
|
|
// Init is called once for the worker to perform any initialization.
|
|
// Init is called once for the worker to perform any initialization.
|
|
|
- Init(config *psiphon.Config) error
|
|
|
|
|
|
|
+ Init(ctx context.Context, config *psiphon.Config) error
|
|
|
// Run is called once, after Init(..), for the worker to perform its
|
|
// Run is called once, after Init(..), for the worker to perform its
|
|
|
// work. The provided context should control the lifetime of the work
|
|
// work. The provided context should control the lifetime of the work
|
|
|
// being performed.
|
|
// being performed.
|
|
@@ -367,7 +367,7 @@ type TunnelWorker struct {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Init implements the Worker interface.
|
|
// Init implements the Worker interface.
|
|
|
-func (w *TunnelWorker) Init(config *psiphon.Config) error {
|
|
|
|
|
|
|
+func (w *TunnelWorker) Init(ctx context.Context, config *psiphon.Config) error {
|
|
|
|
|
|
|
|
// Initialize data store
|
|
// Initialize data store
|
|
|
|
|
|
|
@@ -387,8 +387,8 @@ func (w *TunnelWorker) Init(config *psiphon.Config) error {
|
|
|
// still started: either existing candidate servers may suffice, or the
|
|
// still started: either existing candidate servers may suffice, or the
|
|
|
// remote server list fetch may obtain candidate servers.
|
|
// remote server list fetch may obtain candidate servers.
|
|
|
//
|
|
//
|
|
|
- // TODO: abort import if controller run ctx is cancelled. Currently, this
|
|
|
|
|
- // import will block shutdown.
|
|
|
|
|
|
|
+ // The import will be interrupted if it's still running when the controller
|
|
|
|
|
+ // is stopped.
|
|
|
if w.embeddedServerEntryListFilename != "" {
|
|
if w.embeddedServerEntryListFilename != "" {
|
|
|
w.embeddedServerListWaitGroup = new(sync.WaitGroup)
|
|
w.embeddedServerListWaitGroup = new(sync.WaitGroup)
|
|
|
w.embeddedServerListWaitGroup.Add(1)
|
|
w.embeddedServerListWaitGroup.Add(1)
|
|
@@ -396,6 +396,7 @@ func (w *TunnelWorker) Init(config *psiphon.Config) error {
|
|
|
defer w.embeddedServerListWaitGroup.Done()
|
|
defer w.embeddedServerListWaitGroup.Done()
|
|
|
|
|
|
|
|
err = psiphon.ImportEmbeddedServerEntries(
|
|
err = psiphon.ImportEmbeddedServerEntries(
|
|
|
|
|
+ ctx,
|
|
|
config,
|
|
config,
|
|
|
w.embeddedServerEntryListFilename,
|
|
w.embeddedServerEntryListFilename,
|
|
|
"")
|
|
"")
|
|
@@ -441,7 +442,7 @@ type FeedbackWorker struct {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// Init implements the Worker interface.
|
|
// Init implements the Worker interface.
|
|
|
-func (f *FeedbackWorker) Init(config *psiphon.Config) error {
|
|
|
|
|
|
|
+func (f *FeedbackWorker) Init(ctx context.Context, config *psiphon.Config) error {
|
|
|
|
|
|
|
|
// The datastore is not opened here, with psiphon.OpenDatastore,
|
|
// The datastore is not opened here, with psiphon.OpenDatastore,
|
|
|
// because it is opened/closed transiently in the psiphon.SendFeedback
|
|
// because it is opened/closed transiently in the psiphon.SendFeedback
|