Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix concurrent autoupdate single requests #4344

Merged
Merged
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
2 changes: 1 addition & 1 deletion client/src/app/site/services/auth-check.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ export class AuthCheckService {
if (typeof info === `string`) {
meetingIdString = this.osRouter.getMeetingId(info);
}
if (Number.isNaN(Number(meetingIdString))) {
if (Number.isNaN(Number(meetingIdString)) || +meetingIdString <= 0) {
return false;
}
await this.fetchMeetingIfNotExists(+meetingIdString);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ import { SUBSCRIPTION_SUFFIX } from '../model-request.service';
})
export class AutoupdateCommunicationService {
private autoupdateDataObservable: Observable<AutoupdateReceiveDataContent>;
private openResolvers = new Map<string, (value: number | PromiseLike<number>) => void>();
private openResolvers = new Map<string, ((value: number | PromiseLike<number>) => void)[]>();
private endpointName: string;
private autoupdateEndpointStatus: 'healthy' | 'unhealthy' = `healthy`;
private unhealtyTimeout: any;
Expand Down Expand Up @@ -130,7 +130,11 @@ export class AutoupdateCommunicationService {
public open(streamId: Id | null, description: string, request: ModelRequest, params = {}): Promise<Id> {
return new Promise((resolve, reject) => {
const requestHash = djb2hash(JSON.stringify(request));
this.openResolvers.set(requestHash, resolve);
if (this.openResolvers.has(requestHash)) {
this.openResolvers.get(requestHash).push(resolve);
} else {
this.openResolvers.set(requestHash, [resolve]);
}
this.sharedWorker
.sendMessage(`autoupdate`, {
action: `open`,
Expand Down Expand Up @@ -298,7 +302,7 @@ export class AutoupdateCommunicationService {
return;
}

this.openResolvers.get(data.content.requestHash)(data.content?.streamId);
this.openResolvers.get(data.content.requestHash).forEach(r => r(data.content?.streamId));
this.openResolvers.delete(data.content.requestHash);
}

Expand Down
20 changes: 15 additions & 5 deletions client/src/app/site/services/autoupdate/autoupdate.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export class AutoupdateService {
private _activeRequestObjects: AutoupdateSubscriptionMap = {};
private _mutex = new Mutex();
private _currentQueryParams: QueryParams | null = null;
private _resolveDataReceived: ((value: ModelData) => void)[] = [];
private _resolveDataReceived: { [key: number]: ((value: ModelData) => void)[] } = [];

public constructor(
private httpEndpointService: HttpStreamEndpointService,
Expand Down Expand Up @@ -224,8 +224,13 @@ export class AutoupdateService {
);

let rejectReceivedData: any;
let resolveIdx: number;
const receivedData = new Promise<ModelData>((resolve, reject) => {
this._resolveDataReceived[id] = resolve;
if (this._resolveDataReceived[id]) {
resolveIdx = this._resolveDataReceived[id].push(resolve) - 1;
} else {
this._resolveDataReceived[id] = [resolve];
}
rejectReceivedData = reject;
});
receivedData.catch((e: Error) => {
Expand All @@ -238,9 +243,9 @@ export class AutoupdateService {
close: (): void => {
this.communication.close(id);
delete this._activeRequestObjects[id];
if (this._resolveDataReceived[id]) {
if (this._resolveDataReceived[id] && this._resolveDataReceived[id][resolveIdx]) {
rejectReceivedData(new Error(`Connection canceled`));
delete this._resolveDataReceived[id];
delete this._resolveDataReceived[id][resolveIdx];
}

console.debug(`[autoupdate] stream closed:`, description);
Expand Down Expand Up @@ -323,7 +328,12 @@ export class AutoupdateService {
this.communication.cleanupCollections(requestId, deletedModels);

if (this._resolveDataReceived[requestId]) {
this._resolveDataReceived[requestId](modelData);
for (let i = 0; i < this._resolveDataReceived[requestId].length; i++) {
if (this._resolveDataReceived[requestId][i]) {
this._resolveDataReceived[requestId][i](modelData);
delete this._resolveDataReceived[requestId][i];
}
}
delete this._resolveDataReceived[requestId];
}
}
Expand Down