Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion v2/config/chain.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,9 @@ func chainWarpEndpoint(tag, chainStatus string, warp ChainWarpOptions, detour st
Detour: detour, // register the WARP account along the same path
},
Noise: chainWarpNoise(warp),
MTU: 1280,
// its packets travel inside the main proxy, which adds its own header: 1280 lost every
// packet above ~1200 bytes behind a shadowsocks server, 1000 passed
MTU: 1280,
}
options.Detour = detour
if warp.CleanIP != "" {
Expand Down
2 changes: 1 addition & 1 deletion v2/hcore/custom.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ func StopAndAlert(msgType MessageType, message string) {
SetCoreStatus(CoreStates_STOPPED, msgType, message)

if ss := static.StartedService; ss != nil {
ss.CloseService()
closeService(ss)
static.StartedService = nil
}
}
Expand Down
2 changes: 1 addition & 1 deletion v2/hcore/independent_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func RunInstance(ctx context.Context, hiddifySettings *config.HiddifyOptions, si
// dialer, err := s.libbox.GetInstance().Router().Dialer(context.Background())

func (s *HiddifyInstance) Close() error {
return s.StartedService.CloseService()
return closeService(s.StartedService)
}

func (s *HiddifyInstance) GetContent(url string) (string, error) {
Expand Down
10 changes: 10 additions & 0 deletions v2/hcore/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,11 @@ func NewService(ctx context.Context, options option.Options) (*daemon.StartedSer

content, err := json.MarshalContext(ctx, options)
if err != nil {
closeService(instance)
return nil, err
}
if err := instance.StartOrReloadService(ctx, string(content), nil); err != nil {
closeService(instance)
return nil, err
}

Expand All @@ -59,6 +61,14 @@ func NewService(ctx context.Context, options option.Options) (*daemon.StartedSer
return instance, nil
}

// closeService stops ss and ends its observer goroutines. CloseService alone
// stops only the box and leaves five goroutines running for every service built.
func closeService(ss *daemon.StartedService) error {
err := ss.CloseService()
ss.Close()
return err
}

func (h *HiddifyInstance) UrlTestHistory() *urltest.HistoryStorage {

ins := h.Instance()
Expand Down
2 changes: 1 addition & 1 deletion v2/hcore/start.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,7 @@ func startServiceLocked(ctx context.Context, in *StartRequest) (coreResponse *Co
}
if err := contextErr(ctx); err != nil {
// cancelled while the service was starting: stop it again
if closeErr := instance.CloseService(); closeErr != nil {
if closeErr := closeService(instance); closeErr != nil {
Log(LogLevel_ERROR, LogType_CORE, "closing cancelled service: ", closeErr.Error())
}
return cancelledStart(err)
Expand Down
2 changes: 1 addition & 1 deletion v2/hcore/stop.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func Stop() (coreResponse *CoreInfoResponse, err error) {
return SetCoreStatus(CoreStates_STOPPED, MessageType_ALREADY_STOPPED, ""), nil
}

if err := ss.CloseService(); err != nil {
if err := closeService(ss); err != nil {
static.StartedService = nil
dumpGoroutinesToFile(fmt.Sprint(sWorkingPath, "/data/goroutine-stop.log"))
return errorWrapper(MessageType_UNEXPECTED_ERROR, err)
Expand Down
3 changes: 3 additions & 0 deletions v2/hcore/tunnelservice/tunnel_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,8 @@ func (s *TunnelService) Stop(ctx context.Context, _ *hcommon.Empty) (*TunnelResp
}, nil
}
err := s.box.CloseService()
// CloseService leaves the box's observer goroutines running; Close ends them.
s.box.Close()
if err != nil {
return &TunnelResponse{
Message: err.Error(),
Expand All @@ -131,6 +133,7 @@ func (s *TunnelService) Status(ctx context.Context, _ *hcommon.Empty) (*TunnelRe
func (s *TunnelService) Exit(ctx context.Context, _ *hcommon.Empty) (*TunnelResponse, error) {
if s.box != nil {
s.box.CloseService()
s.box.Close()
}
go func() {
<-time.After(time.Second * 1)
Expand Down