Skip to content

Commit

Permalink
fix: do not send package via outdated session (#1559)
Browse files Browse the repository at this point in the history
Signed-off-by: Niall Shaw <niall.shaw@absa.africa>
  • Loading branch information
niall-shaw committed Aug 30, 2023
1 parent c0d9304 commit de6a735
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions packages/core/src/agent/TransportService.ts
Expand Up @@ -13,6 +13,14 @@ export class TransportService {
public transportSessionTable: TransportSessionTable = {}

public saveSession(session: TransportSession) {
if (session.connectionId) {
const oldSessions = this.getExistingSessionsForConnectionIdAndType(session.connectionId, session.type)
oldSessions.forEach((oldSession) => {
if (oldSession) {
this.removeSession(oldSession)
}
})
}
this.transportSessionTable[session.id] = session
}

Expand Down Expand Up @@ -40,6 +48,12 @@ export class TransportService {
public removeSession(session: TransportSession) {
delete this.transportSessionTable[session.id]
}

private getExistingSessionsForConnectionIdAndType(connectionId: string, type: string) {
return Object.values(this.transportSessionTable).filter(
(session) => session?.connectionId === connectionId && session.type === type
)
}
}

interface TransportSessionTable {
Expand Down

0 comments on commit de6a735

Please sign in to comment.