From 3dd993a76a5e5d87a0b31e1eff5093958f239021 Mon Sep 17 00:00:00 2001 From: Julia Johannesen Date: Sat, 17 Aug 2024 14:27:43 -0400 Subject: [PATCH] Add IP and user ID to connection close message --- .../backend/src/server/api/StreamingApiServerService.ts | 2 +- packages/backend/src/server/api/stream/Connection.ts | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/packages/backend/src/server/api/StreamingApiServerService.ts b/packages/backend/src/server/api/StreamingApiServerService.ts index 19c78fd4d1..2070ab6106 100644 --- a/packages/backend/src/server/api/StreamingApiServerService.ts +++ b/packages/backend/src/server/api/StreamingApiServerService.ts @@ -159,7 +159,7 @@ export class StreamingApiServerService { this.cacheService, this.channelFollowingService, this.loggerService, - user, app, + user, app, requestIp, rateLimiter, ); diff --git a/packages/backend/src/server/api/stream/Connection.ts b/packages/backend/src/server/api/stream/Connection.ts index 0914cdbb22..b71a99b89e 100644 --- a/packages/backend/src/server/api/stream/Connection.ts +++ b/packages/backend/src/server/api/stream/Connection.ts @@ -57,6 +57,7 @@ export default class Connection { user: MiUser | null | undefined, token: MiAccessToken | null | undefined, + private ip: string, rateLimiter: () => Promise, ) { if (user) this.user = user; @@ -127,7 +128,10 @@ export default class Connection { if (shouldRateLimit) return; if (this.closingConnection) return; } else { - this.logger.warn('Closing a connection due to an excessive influx of messages.'); + let connectionInfo = `IP ${this.ip}`; + if (this.user) connectionInfo += `, user ID ${this.user.id}`; + + this.logger.warn(`Closing a connection (${connectionInfo}) due to an excessive influx of messages.`); this.closingConnection = true; this.wsConnection.close(1008, 'Please stop spamming the streaming API.'); return;