Browse Source

retry on port allocation

v2ray 9 năm trước cách đây
mục cha
commit
edd9885d0e
1 tập tin đã thay đổi với 16 bổ sung10 xóa
  1. 16 10
      shell/point/inbound_detour_dynamic.go

+ 16 - 10
shell/point/inbound_detour_dynamic.go

@@ -8,6 +8,7 @@ import (
 	"github.com/v2ray/v2ray-core/common/dice"
 	"github.com/v2ray/v2ray-core/common/log"
 	v2net "github.com/v2ray/v2ray-core/common/net"
+	"github.com/v2ray/v2ray-core/common/retry"
 	"github.com/v2ray/v2ray-core/proxy"
 	proxyrepo "github.com/v2ray/v2ray-core/proxy/repo"
 )
@@ -98,20 +99,25 @@ func (this *InboundDetourHandlerDynamic) refresh() error {
 	newIchs := make([]proxy.InboundHandler, config.Allocation.Concurrency)
 
 	for idx, _ := range newIchs {
-		port := this.pickUnusedPort()
-		ich, err := proxyrepo.CreateInboundHandler(config.Protocol, this.space, config.Settings, &proxy.InboundHandlerMeta{
-			Address: config.ListenOn, Port: port, Tag: config.Tag, StreamSettings: config.StreamSettings})
+		err := retry.Timed(5, 100).On(func() error {
+			port := this.pickUnusedPort()
+			ich, err := proxyrepo.CreateInboundHandler(config.Protocol, this.space, config.Settings, &proxy.InboundHandlerMeta{
+				Address: config.ListenOn, Port: port, Tag: config.Tag, StreamSettings: config.StreamSettings})
+			if err != nil {
+				return err
+			}
+			err = ich.Start()
+			if err != nil {
+				return err
+			}
+			this.portsInUse[port] = true
+			newIchs[idx] = ich
+			return nil
+		})
 		if err != nil {
 			log.Error("Point: Failed to create inbound connection handler: ", err)
 			return err
 		}
-		err = ich.Start()
-		if err != nil {
-			log.Error("Point: Failed to start inbound connection handler: ", err)
-			return err
-		}
-		this.portsInUse[port] = true
-		newIchs[idx] = ich
 	}
 
 	this.Lock()