Add IP and user ID to connection close message
This commit is contained in:
		
							parent
							
								
									c5f7dcbb7e
								
							
						
					
					
						commit
						3dd993a76a
					
				
					 2 changed files with 6 additions and 2 deletions
				
			
		| 
						 | 
					@ -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,
 | 
				
			||||||
			);
 | 
								);
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -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;
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue