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
5 changes: 5 additions & 0 deletions app/services/app/app.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ import { StreamAvatarService } from 'services/stream-avatar/stream-avatar-servic
import { NavigationService } from 'services/navigation';
import { StreamingService } from 'services/streaming';
import { VirtualWebcamService } from 'services/virtual-webcam';
import { WebsocketService } from 'services/websocket';

interface IAppState {
loading: boolean;
Expand Down Expand Up @@ -104,6 +105,7 @@ export class AppService extends StatefulService<IAppState> {
@Inject() private navigationService: NavigationService;
@Inject() private streamingService: StreamingService;
@Inject() private virtualWebcamService: VirtualWebcamService;
@Inject() private websocketService: WebsocketService;

static initialState: IAppState = {
loading: true,
Expand Down Expand Up @@ -213,6 +215,8 @@ export class AppService extends StatefulService<IAppState> {
this.streamAvatarService.stopAvatarProcess();
this.crashReporterService.beginShutdown();
this.shutdownStarted.next();
this.recentEventsService.shutdown();
this.websocketService.disconnect();
this.keyListenerService.shutdown();
this.platformAppsService.unloadAllApps();
await this.usageStatisticsService.flushEvents();
Expand All @@ -232,6 +236,7 @@ export class AppService extends StatefulService<IAppState> {
obs.NodeObs.RemoveVolmeterCallback();
obs.NodeObs.OBS_service_removeCallback();
obs.IPC.disconnect();
this.realmService.close();

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This only closes the worker window's Realm instance. To fully fix the stale-reader/unclean-close risk described in the PR, shutdown needs to close Realm in every renderer that opened it, or move the connection so only the worker opens it.

this.crashReporterService.endShutdown();
electron.ipcRenderer.send('shutdownComplete');
}, 300);
Expand Down
5 changes: 5 additions & 0 deletions app/services/realm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ export class RealmService extends Service {
this.ephemeralDb = await Realm.open(this.ephemeralConfig as any);
}

close() {
this.persistentDb?.close();
this.ephemeralDb?.close();
}

executeMigrations(oldRealm: Realm, newRealm: Realm) {
Object.values(RealmService.registeredClasses).forEach(klass => {
klass.onMigration(oldRealm, newRealm);
Expand Down
4 changes: 4 additions & 0 deletions app/services/recent-events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,10 @@ export class RecentEventsService extends StatefulService<IRecentEventsState> {
this.unsubscribeFromSocketConnection();
}

shutdown() {
this.unsubscribeFromSocketConnection();
}

fetchRecentEvents() {
const typeString = this.getEventTypesString();
// eslint-disable-next-line
Expand Down
7 changes: 7 additions & 0 deletions app/services/websocket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,13 @@ export class WebsocketService extends Service {
});
}

disconnect() {
if (this.socket) {
this.socket.disconnect();
this.socket = undefined;
}
}

private log(message: string, ...args: any[]) {
console.debug(`WS: ${message}`, ...args);

Expand Down
Loading