Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions packages/dota/src/db/RedisClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ class RedisClient {
private constructor() {
this.client = createClient({ url: `redis://${process.env.HOST_REDIS}:6379` })
this.subscriber = this.client.duplicate()

// Handle process exit to close Redis connections properly
process.on('exit', this.closeConnections.bind(this))
process.on('SIGINT', this.closeConnections.bind(this))
process.on('SIGTERM', this.closeConnections.bind(this))
}

public async connect(
Expand All @@ -36,6 +41,16 @@ class RedisClient {
if (!RedisClient.instance) RedisClient.instance = new RedisClient()
return RedisClient.instance
}

private async closeConnections() {
try {
await this.client.quit()
await this.subscriber.quit()
logger.info('Redis connections closed successfully')
} catch (error) {
logger.error('Error closing Redis connections', { error })
}
}
}

export default RedisClient
10 changes: 9 additions & 1 deletion packages/dota/src/dota/GSIServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ const allowedOrigins = [
]
class GSIServer {
io: Server
private inactiveTokenInterval: NodeJS.Timeout | null = null

constructor() {
logger.info('Starting GSI Server!')
Expand Down Expand Up @@ -145,12 +146,19 @@ class GSIServer {

// Set up the repeating timer
// eslint-disable-next-line @typescript-eslint/no-misused-promises
setInterval(checkForInactiveTokens, TOKEN_TIMEOUT)
this.inactiveTokenInterval = setInterval(checkForInactiveTokens, TOKEN_TIMEOUT)
}

init() {
return this
}

close() {
if (this.inactiveTokenInterval) {
clearInterval(this.inactiveTokenInterval)
this.inactiveTokenInterval = null
}
}
}

export default GSIServer
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,12 @@ export async function checkCallAndMemory(regexPattern: RegExp, userCount: number

prevCallCount = callLength
}, 1000)

// Clear memory after tests
return () => {
clearInterval(interval)
twitchChatSpy.mockClear()
global.gc() // Trigger garbage collection if available
}
})
}
Loading