Skip to content

Commit dc82602

Browse files
committed
Merge branch 'v2-feature-main'
2 parents 4f7736e + 7510bc4 commit dc82602

115 files changed

Lines changed: 2100 additions & 1205 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

cache/memcache/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/dobyte/due/cache/memcache/v2
22

3-
go 1.24.0
3+
go 1.25.0
44

55
require (
66
github.com/bradfitz/gomemcache v0.0.0-20250403215159-8d39553ac7cf
7-
github.com/dobyte/due/v2 v2.5.1
8-
golang.org/x/sync v0.19.0
7+
github.com/dobyte/due/v2 v2.5.4
8+
golang.org/x/sync v0.20.0
99
)
1010

1111
require (

cache/memcache/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
3636
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
3737
golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4=
3838
golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
39-
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
40-
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
39+
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
40+
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
4141
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
4242
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
4343
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

cache/redis/go.mod

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
module github.com/dobyte/due/cache/redis/v2
22

3-
go 1.24.0
3+
go 1.25.0
44

55
require (
6-
github.com/dobyte/due/v2 v2.5.1
6+
github.com/dobyte/due/v2 v2.5.4
77
github.com/redis/go-redis/v9 v9.17.2
8-
golang.org/x/sync v0.19.0
8+
golang.org/x/sync v0.20.0
99
)
1010

1111
require (

cache/redis/go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ github.com/twitchyliquid64/golang-asm v0.15.1 h1:SU5vSMR7hnwNxj24w34ZyCi/FmDZTkS
4444
github.com/twitchyliquid64/golang-asm v0.15.1/go.mod h1:a1lVb/DtPvCB8fslRZhAngC2+aY1QWCk3Cedj/Gdt08=
4545
golang.org/x/arch v0.11.0 h1:KXV8WWKCXm6tRpLirl2szsO5j/oOODwZf4hATmGVNs4=
4646
golang.org/x/arch v0.11.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
47-
golang.org/x/sync v0.19.0 h1:vV+1eWNmZ5geRlYjzm2adRgW2/mcpevXNg50YZtPCE4=
48-
golang.org/x/sync v0.19.0/go.mod h1:9KTHXmSnoGruLpwFjVSX0lNNA75CykiMECbovNTZqGI=
47+
golang.org/x/sync v0.20.0 h1:e0PTpb7pjO8GAtTs2dQ6jYa5BWYlMuX047Dco/pItO4=
48+
golang.org/x/sync v0.20.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0=
4949
golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA=
5050
golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
5151
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=

cluster/cluster.go

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -117,25 +117,28 @@ type Message struct {
117117
}
118118

119119
type PushArgs struct {
120-
GID string // 网关ID,会话类型为用户时可忽略此参数
121-
Kind session.Kind // 会话类型,session.Conn 或 session.User
122-
Target int64 // 会话目标,CID 或 UID
123-
Message *Message // 推送消息
124-
Ack bool // 是否需要响应推送结果
120+
GID string // 网关ID,会话类型为用户时可忽略此参数
121+
Kind session.Kind // 会话类型,session.Conn 或 session.User
122+
Target int64 // 会话目标,CID 或 UID
123+
Message *Message // 推送消息
124+
Disconnect bool // 是否在推送消息后优雅地断开连接
125+
Ack bool // 是否需要响应推送结果
125126
}
126127

127128
type MulticastArgs struct {
128-
GID string // 网关ID,会话类型为用户时可忽略此参数
129-
Kind session.Kind // 会话类型,session.Conn 或 session.User
130-
Targets []int64 // 会话目标,CID 或 UID
131-
Message *Message // 组播消息
132-
Ack bool // 是否需要响应推送结果
129+
GID string // 网关ID,会话类型为用户时可忽略此参数
130+
Kind session.Kind // 会话类型,session.Conn 或 session.User
131+
Targets []int64 // 会话目标,CID 或 UID
132+
Message *Message // 组播消息
133+
Disconnect bool // 是否在推送消息后优雅地断开连接
134+
Ack bool // 是否需要响应推送结果
133135
}
134136

135137
type BroadcastArgs struct {
136-
Kind session.Kind // 会话类型,session.Conn 或 session.User
137-
Message *Message // 消息
138-
Ack bool // 是否需要响应推送结果
138+
Kind session.Kind // 会话类型,session.Conn 或 session.User
139+
Message *Message // 消息
140+
Disconnect bool // 是否在推送消息后优雅地断开连接
141+
Ack bool // 是否需要响应推送结果
139142
}
140143

141144
type SubscribeArgs struct {
@@ -153,9 +156,10 @@ type UnsubscribeArgs struct {
153156
}
154157

155158
type PublishArgs struct {
156-
Channel string // 频道
157-
Message *Message // 消息
158-
Ack bool // 是否需要响应推送结果
159+
Channel string // 频道
160+
Message *Message // 消息
161+
Disconnect bool // 是否在推送消息后优雅地断开连接
162+
Ack bool // 是否需要响应推送结果
159163
}
160164

161165
type TriggerArgs struct {

cluster/gate/gate.go

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import (
1212
"fmt"
1313
"sync"
1414
"sync/atomic"
15+
"time"
1516

1617
"github.com/dobyte/due/v2/cluster"
1718
"github.com/dobyte/due/v2/component"
@@ -149,35 +150,31 @@ func (g *Gate) handleConnect(conn network.Conn) {
149150

150151
cid, uid := conn.ID(), conn.UID()
151152

152-
ctx, cancel := context.WithTimeout(g.ctx, g.opts.timeout)
153-
g.proxy.trigger(ctx, cluster.Connect, cid, uid)
154-
cancel()
153+
g.proxy.trigger(g.ctx, cluster.Connect, cid, uid)
155154
}
156155

157156
// 处理断开连接
158157
func (g *Gate) handleDisconnect(conn network.Conn) {
159158
g.session.RemConn(conn)
160159

161-
if cid, uid := conn.ID(), conn.UID(); uid != 0 {
162-
ctx, cancel := context.WithTimeout(g.ctx, g.opts.timeout)
160+
cid, uid := conn.ID(), conn.UID()
161+
162+
if uid != 0 {
163+
ctx, cancel := context.WithTimeout(g.ctx, 3*time.Second)
163164
_ = g.proxy.unbindGate(ctx, cid, uid)
164-
g.proxy.trigger(ctx, cluster.Disconnect, cid, uid)
165-
cancel()
166-
} else {
167-
ctx, cancel := context.WithTimeout(g.ctx, g.opts.timeout)
168-
g.proxy.trigger(ctx, cluster.Disconnect, cid, uid)
169165
cancel()
170166
}
171167

168+
g.proxy.trigger(g.ctx, cluster.Disconnect, cid, uid)
169+
172170
g.wg.Done()
173171
}
174172

175173
// 处理接收到的消息
176174
func (g *Gate) handleReceive(conn network.Conn, data []byte) {
177175
cid, uid := conn.ID(), conn.UID()
178-
ctx, cancel := context.WithTimeout(g.ctx, g.opts.timeout)
179-
g.proxy.deliver(ctx, cid, uid, data)
180-
cancel()
176+
177+
g.proxy.deliver(g.ctx, cid, uid, data)
181178
}
182179

183180
// 启动传输服务器
@@ -218,7 +215,7 @@ func (g *Gate) registerServiceInstance() {
218215
Metadata: g.opts.metadata,
219216
}
220217

221-
ctx, cancel := context.WithTimeout(g.ctx, defaultTimeout)
218+
ctx, cancel := context.WithTimeout(g.ctx, 3*time.Second)
222219
defer cancel()
223220

224221
if err := g.opts.registry.Register(ctx, g.instance); err != nil {
@@ -234,7 +231,7 @@ func (g *Gate) refreshServiceInstance() {
234231

235232
g.instance.State = g.getState().String()
236233

237-
ctx, cancel := context.WithTimeout(g.ctx, defaultTimeout)
234+
ctx, cancel := context.WithTimeout(g.ctx, 3*time.Second)
238235
defer cancel()
239236

240237
if err := g.opts.registry.Register(ctx, g.instance); err != nil {
@@ -244,7 +241,7 @@ func (g *Gate) refreshServiceInstance() {
244241

245242
// 解注册服务实例
246243
func (g *Gate) deregisterServiceInstance() {
247-
ctx, cancel := context.WithTimeout(g.ctx, defaultTimeout)
244+
ctx, cancel := context.WithTimeout(g.ctx, 3*time.Second)
248245
defer cancel()
249246

250247
if err := g.opts.registry.Deregister(ctx, g.instance); err != nil {

0 commit comments

Comments
 (0)