Skip to content

Commit 712cad8

Browse files
committed
Fix memory issue
1 parent db376d0 commit 712cad8

File tree

1 file changed

+1
-33
lines changed

1 file changed

+1
-33
lines changed

redis.go

+1-33
Original file line numberDiff line numberDiff line change
@@ -25,18 +25,12 @@ type RedisTransport struct {
2525
client *redis.Client
2626
subscribers *SubscriberList
2727
dispatcherPoolSize int
28-
dispatcher chan SubscriberPayload
2928
closed chan any
3029
publishScript *redis.Script
3130
closedOnce sync.Once
3231
redisChannel string
3332
}
3433

35-
type SubscriberPayload struct {
36-
subscriber *LocalSubscriber
37-
payload Update
38-
}
39-
4034
func NewRedisTransport(
4135
logger Logger,
4236
address string,
@@ -76,7 +70,6 @@ func NewRedisTransportInstance(
7670
subscribers: NewSubscriberList(subscribersSize),
7771
dispatcherPoolSize: dispatcherPoolSize,
7872
publishScript: redis.NewScript(publishScript),
79-
dispatcher: make(chan SubscriberPayload),
8073
closed: make(chan any),
8174
redisChannel: redisChannel,
8275
}
@@ -103,19 +96,6 @@ func NewRedisTransportInstance(
10396
transport.subscribe(subscribeCtx, subscribeCancel, subscriber)
10497
}()
10598

106-
wg.Add(dispatcherPoolSize)
107-
for range dispatcherPoolSize {
108-
go func() {
109-
defer wg.Done()
110-
transport.dispatch()
111-
}()
112-
}
113-
114-
go func() {
115-
wg.Wait()
116-
close(transport.dispatcher)
117-
}()
118-
11999
return transport, nil
120100
}
121101

@@ -232,24 +212,12 @@ func (t *RedisTransport) subscribe(ctx context.Context, cancel context.CancelFun
232212
t.Lock()
233213
for _, subscriber := range t.subscribers.MatchAny(&update) {
234214
update.Topics = topics
235-
t.dispatcher <- SubscriberPayload{subscriber, update}
215+
subscriber.Dispatch(&update, false)
236216
}
237217
t.Unlock()
238218
}
239219
}
240220

241-
func (t *RedisTransport) dispatch() {
242-
for {
243-
select {
244-
case message := <-t.dispatcher:
245-
message.subscriber.Dispatch(&message.payload, false)
246-
case <-t.closed:
247-
248-
return
249-
}
250-
}
251-
}
252-
253221
var (
254222
_ Transport = (*RedisTransport)(nil)
255223
_ TransportSubscribers = (*RedisTransport)(nil)

0 commit comments

Comments
 (0)