Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: do not send package via outdated session #1559

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/core/src/agent/TransportService.ts
Original file line number Diff line number Diff line change
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
)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can limit it to one session per type and connection id? That way we don't have to add web socket specific logic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I'm happy with that also. Bug was only found in WebSocket, that's why I made it this way, but happy to change :)


interface TransportSessionTable {
Expand Down