Add IP and user ID to connection close message

This commit is contained in:
Julia Johannesen 2024-08-17 14:27:43 -04:00
parent c5f7dcbb7e
commit 3dd993a76a
No known key found for this signature in database
GPG key ID: 4A1377AF3E7FBC46
2 changed files with 6 additions and 2 deletions

View file

@ -159,7 +159,7 @@ export class StreamingApiServerService {
this.cacheService, this.cacheService,
this.channelFollowingService, this.channelFollowingService,
this.loggerService, this.loggerService,
user, app, user, app, requestIp,
rateLimiter, rateLimiter,
); );

View file

@ -57,6 +57,7 @@ export default class Connection {
user: MiUser | null | undefined, user: MiUser | null | undefined,
token: MiAccessToken | null | undefined, token: MiAccessToken | null | undefined,
private ip: string,
rateLimiter: () => Promise<boolean>, rateLimiter: () => Promise<boolean>,
) { ) {
if (user) this.user = user; if (user) this.user = user;
@ -127,7 +128,10 @@ export default class Connection {
if (shouldRateLimit) return; if (shouldRateLimit) return;
if (this.closingConnection) return; if (this.closingConnection) return;
} else { } 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.closingConnection = true;
this.wsConnection.close(1008, 'Please stop spamming the streaming API.'); this.wsConnection.close(1008, 'Please stop spamming the streaming API.');
return; return;