mirror of
https://activitypub.software/TransFem-org/Sharkey.git
synced 2025-09-18 21:38:07 +00:00
merge: StreamingApiServerService: handle websocket errors from client gracefully (!1166)
View MR for information: https://activitypub.software/TransFem-org/Sharkey/-/merge_requests/1166 Approved-by: Hazelnoot <acomputerdog@gmail.com> Approved-by: Marie <github@yuugi.dev>
This commit is contained in:
commit
ae65642ffb
1 changed files with 9 additions and 0 deletions
|
@ -12,6 +12,7 @@ import { DI } from '@/di-symbols.js';
|
|||
import type { UsersRepository, MiAccessToken, MiUser, NoteReactionsRepository, NotesRepository, NoteFavoritesRepository } from '@/models/_.js';
|
||||
import type { Config } from '@/config.js';
|
||||
import type { Keyed, RateLimit } from '@/misc/rate-limit-utils.js';
|
||||
import { renderInlineError } from '@/misc/render-inline-error.js';
|
||||
import { NotificationService } from '@/core/NotificationService.js';
|
||||
import { bindThis } from '@/decorators.js';
|
||||
import { CacheService } from '@/core/CacheService.js';
|
||||
|
@ -20,6 +21,7 @@ import { UserService } from '@/core/UserService.js';
|
|||
import { ChannelFollowingService } from '@/core/ChannelFollowingService.js';
|
||||
import { getIpHash } from '@/misc/get-ip-hash.js';
|
||||
import { LoggerService } from '@/core/LoggerService.js';
|
||||
import type Logger from '@/logger.js';
|
||||
import { SkRateLimiterService } from '@/server/SkRateLimiterService.js';
|
||||
import { QueryService } from '@/core/QueryService.js';
|
||||
import { AuthenticateService, AuthenticationError } from './AuthenticateService.js';
|
||||
|
@ -38,6 +40,7 @@ export class StreamingApiServerService implements OnApplicationShutdown {
|
|||
#connectionsByClient = new Map<string, Set<WebSocket.WebSocket>>(); // key: IP / user ID -> value: connection
|
||||
#cleanConnectionsIntervalId: NodeJS.Timeout | null = null;
|
||||
readonly #globalEv = new EventEmitter();
|
||||
#logger: Logger;
|
||||
|
||||
constructor(
|
||||
@Inject(DI.redisForSub)
|
||||
|
@ -69,6 +72,7 @@ export class StreamingApiServerService implements OnApplicationShutdown {
|
|||
private config: Config,
|
||||
) {
|
||||
this.redisForSub.on('message', this.onRedis);
|
||||
this.#logger = loggerService.getLogger('streaming', 'coral');
|
||||
}
|
||||
|
||||
@bindThis
|
||||
|
@ -222,6 +226,11 @@ export class StreamingApiServerService implements OnApplicationShutdown {
|
|||
}
|
||||
});
|
||||
|
||||
ws.once('error', (e) => {
|
||||
this.#logger.error(`Unhandled error in Streaming Api: ${renderInlineError(e)}`);
|
||||
ws.terminate();
|
||||
});
|
||||
|
||||
this.#wss.emit('connection', ws, request, {
|
||||
stream, user, app,
|
||||
});
|
||||
|
|
Loading…
Add table
Reference in a new issue