Skip to content

Commit

Permalink
fix(shutdown): fix channels not being cleared correctly (#444)
Browse files Browse the repository at this point in the history
  • Loading branch information
samuelmasse committed Apr 13, 2022
1 parent 62ea415 commit 95fde0f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/channels/src/base/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ export interface Channel {
}

export interface ChannelStateManager {
scopes(): string[]
set(scope: string, val: any): boolean
get(scope: string): any
del(scope: string): void
Expand Down
6 changes: 5 additions & 1 deletion packages/channels/src/base/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ export abstract class ChannelService<
protected manager?: ChannelStateManager

get scopes() {
return Object.keys(this.states)
if (this.manager) {
return this.manager.scopes()
} else {
return Object.keys(this.states)
}
}

async setup() {}
Expand Down
5 changes: 5 additions & 0 deletions packages/server/src/instances/clearing/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,11 @@ export class InstanceClearingService extends Service {

for (const channel of this.channels.list()) {
channel.stateManager({
scopes: () =>
this.statesCache
.keys()
.filter((x) => x.startsWith(channel.meta.id))
.map((x) => this.statesCache.getValues(x)[1]),
set: (providerName, val) => this.statesCache.set(channel.meta.id, providerName, val),
get: (providerName) => {
return (
Expand Down
7 changes: 5 additions & 2 deletions packages/server/src/instances/lifetime/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,12 @@ export class InstanceLifetimeService extends Service {
async destroy() {
for (const channel of this.channels.list()) {
for (const scope of channel.scopes) {
const provider = await this.providers.getByName(scope)
const conduit = await this.conduits.getByProviderAndChannel(provider.id, channel.meta.id)
const provider = await this.providers.fetchByName(scope)
if (!provider) {
continue
}

const conduit = await this.conduits.getByProviderAndChannel(provider.id, channel.meta.id)
await this.stop(conduit.id)
}
}
Expand Down

0 comments on commit 95fde0f

Please sign in to comment.