소스 검색

fix(inbound): request an xray restart when toggling a routed MTProto inbound

AddInbound, DelInbound and UpdateInbound all flag needRestart when an inbound
routes MTProto through xray, so the egress SOCKS bridge is regenerated. Only
SetInboundEnable's local path omitted it, so toggling a routed MTProto inbound
off then on left the bridge out of the running config while the sidecar dialed
its loopback port, blackholing that inbound until an unrelated restart. Flag the
restart on the local enable path too.
MHSanaei 1 일 전
부모
커밋
c3f0378e68
2개의 변경된 파일31개의 추가작업 그리고 0개의 파일을 삭제
  1. 4 0
      internal/web/service/inbound.go
  2. 27 0
      internal/web/service/inbound_mtproto_txfail_test.go

+ 4 - 0
internal/web/service/inbound.go

@@ -1103,6 +1103,10 @@ func (s *InboundService) SetInboundEnable(id int, enable bool) (bool, error) {
 		return false, nil
 	}
 
+	if mtprotoRoutesThroughXray(inbound) {
+		needRestart = true
+	}
+
 	if !push {
 		return true, nil
 	}

+ 27 - 0
internal/web/service/inbound_mtproto_txfail_test.go

@@ -51,3 +51,30 @@ func TestUpdateInboundLocalMtprotoDefersPushUntilCommit(t *testing.T) {
 		t.Fatalf("the MTProto sidecar push ran %d time(s) inside the failed transaction; it must be deferred until the commit succeeds", n)
 	}
 }
+
+// Re-enabling a routed MTProto inbound must request an xray restart: the egress
+// SOCKS bridge is only injected for enabled inbounds, so the running config
+// needs regenerating or the sidecar dials a bridge that is not there.
+func TestSetInboundEnableRoutedMtprotoRequestsRestart(t *testing.T) {
+	setupConflictDB(t)
+
+	mgr := runtime.NewManager(runtime.LocalDeps{APIPort: func() int { return 0 }})
+	mgr.SetLocalRuntimeOverride(&fakeNodeRuntime{})
+	runtime.SetManager(mgr)
+	t.Cleanup(func() { runtime.SetManager(nil) })
+
+	seedInboundConflict(t, "mt-route", "", 46160, model.MTProto, "",
+		`{"clients":[{"email":"mtr","secret":"`+mtprotoTestSecretA+`","enable":true}],"routeThroughXray":true,"routeXrayPort":12345}`)
+	seeded := loadInboundByTag(t, "mt-route")
+	if err := database.GetDB().Model(&model.Inbound{}).Where("id = ?", seeded.Id).Update("enable", false).Error; err != nil {
+		t.Fatalf("force disable: %v", err)
+	}
+
+	needRestart, err := (&InboundService{}).SetInboundEnable(seeded.Id, true)
+	if err != nil {
+		t.Fatalf("SetInboundEnable: %v", err)
+	}
+	if !needRestart {
+		t.Fatal("re-enabling a routed MTProto inbound must request an xray restart to re-inject the egress bridge")
+	}
+}