close channel on client discard
This commit is contained in:
parent
d0795bd849
commit
34d7ac0808
|
@ -5,6 +5,8 @@
|
||||||
|
|
||||||
- Fixed rate limiter rules matching to acount for the `Audience` field.
|
- Fixed rate limiter rules matching to acount for the `Audience` field.
|
||||||
|
|
||||||
|
- Force closing the realtime connection on unregistering a client (aka. on `app.SubscriptionsBroker().Unregister(clientId)`)
|
||||||
|
|
||||||
- Minor UI fixes (fixed duplicate record control, removed duplicated id field in the record preview, hide Impersonate button for non-auth records, auto sort rate limit rules, etc.).
|
- Minor UI fixes (fixed duplicate record control, removed duplicated id field in the record preview, hide Impersonate button for non-auth records, auto sort rate limit rules, etc.).
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ func (b *Broker) Register(client Client) {
|
||||||
b.store.Set(client.Id(), client)
|
b.store.Set(client.Id(), client)
|
||||||
}
|
}
|
||||||
|
|
||||||
// Unregister removes a single client by its id.
|
// Unregister removes a single client by its id and marks it as discarded.
|
||||||
//
|
//
|
||||||
// If client with clientId doesn't exist, this method does nothing.
|
// If client with clientId doesn't exist, this method does nothing.
|
||||||
func (b *Broker) Unregister(clientId string) {
|
func (b *Broker) Unregister(clientId string) {
|
||||||
|
|
|
@ -32,6 +32,8 @@ type Client interface {
|
||||||
Id() string
|
Id() string
|
||||||
|
|
||||||
// Channel returns the client's communication channel.
|
// Channel returns the client's communication channel.
|
||||||
|
//
|
||||||
|
// NB! The channel shouldn't be used after calling Discard().
|
||||||
Channel() chan Message
|
Channel() chan Message
|
||||||
|
|
||||||
// Subscriptions returns a shallow copy of the client subscriptions matching the prefixes.
|
// Subscriptions returns a shallow copy of the client subscriptions matching the prefixes.
|
||||||
|
@ -65,8 +67,8 @@ type Client interface {
|
||||||
// Get retrieves the key value from the client's context.
|
// Get retrieves the key value from the client's context.
|
||||||
Get(key string) any
|
Get(key string) any
|
||||||
|
|
||||||
// Discard marks the client as "discarded", meaning that it
|
// Discard marks the client as "discarded" (and closes its channel),
|
||||||
// shouldn't be used anymore for sending new messages.
|
// meaning that it shouldn't be used anymore for sending new messages.
|
||||||
//
|
//
|
||||||
// It is safe to call Discard() multiple times.
|
// It is safe to call Discard() multiple times.
|
||||||
Discard()
|
Discard()
|
||||||
|
@ -257,7 +259,13 @@ func (c *DefaultClient) Discard() {
|
||||||
c.mux.Lock()
|
c.mux.Lock()
|
||||||
defer c.mux.Unlock()
|
defer c.mux.Unlock()
|
||||||
|
|
||||||
|
if c.isDiscarded {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
c.isDiscarded = true
|
c.isDiscarded = true
|
||||||
|
|
||||||
|
close(c.channel)
|
||||||
}
|
}
|
||||||
|
|
||||||
// IsDiscarded implements the [Client.IsDiscarded] interface method.
|
// IsDiscarded implements the [Client.IsDiscarded] interface method.
|
||||||
|
|
Loading…
Reference in New Issue