94485: Fix initialization deadlock when backend is unavailable

When the REST server can't be found, `getEndpoint` errors out, no request gets sent, which causes `fetchRequest` to never emit.

Because of this the `checkTokenCookie$` effect would get deadlocked and initialization would never complete.
This commit is contained in:
Yury Bondarenko
2022-09-20 16:15:13 +02:00
parent 31167a3ce4
commit c844423fc3
2 changed files with 12 additions and 6 deletions

View File

@@ -111,7 +111,6 @@ describe(`AuthRequestService`, () => {
body: undefined, body: undefined,
options, options,
})); }));
expect((service as any).fetchRequest).toHaveBeenCalledWith(requestID);
}); });
}); });
}); });
@@ -151,7 +150,6 @@ describe(`AuthRequestService`, () => {
body: { content: 'something' }, body: { content: 'something' },
options, options,
})); }));
expect((service as any).fetchRequest).toHaveBeenCalledWith(requestID);
}); });
}); });
}); });

View File

@@ -58,7 +58,9 @@ export abstract class AuthRequestService {
public postToEndpoint(method: string, body?: any, options?: HttpOptions): Observable<RemoteData<AuthStatus>> { public postToEndpoint(method: string, body?: any, options?: HttpOptions): Observable<RemoteData<AuthStatus>> {
const requestId = this.requestService.generateRequestId(); const requestId = this.requestService.generateRequestId();
this.halService.getEndpoint(this.linkName).pipe( const endpoint$ = this.halService.getEndpoint(this.linkName);
endpoint$.pipe(
filter((href: string) => isNotEmpty(href)), filter((href: string) => isNotEmpty(href)),
map((endpointURL) => this.getEndpointByMethod(endpointURL, method)), map((endpointURL) => this.getEndpointByMethod(endpointURL, method)),
distinctUntilChanged(), distinctUntilChanged(),
@@ -68,7 +70,9 @@ export abstract class AuthRequestService {
this.requestService.send(request); this.requestService.send(request);
}); });
return this.fetchRequest(requestId); return endpoint$.pipe(
switchMap(() => this.fetchRequest(requestId)),
);
} }
/** /**
@@ -79,7 +83,9 @@ export abstract class AuthRequestService {
public getRequest(method: string, options?: HttpOptions, ...linksToFollow: FollowLinkConfig<any>[]): Observable<RemoteData<AuthStatus>> { public getRequest(method: string, options?: HttpOptions, ...linksToFollow: FollowLinkConfig<any>[]): Observable<RemoteData<AuthStatus>> {
const requestId = this.requestService.generateRequestId(); const requestId = this.requestService.generateRequestId();
this.halService.getEndpoint(this.linkName).pipe( const endpoint$ = this.halService.getEndpoint(this.linkName);
endpoint$.pipe(
filter((href: string) => isNotEmpty(href)), filter((href: string) => isNotEmpty(href)),
map((endpointURL) => this.getEndpointByMethod(endpointURL, method, ...linksToFollow)), map((endpointURL) => this.getEndpointByMethod(endpointURL, method, ...linksToFollow)),
distinctUntilChanged(), distinctUntilChanged(),
@@ -89,7 +95,9 @@ export abstract class AuthRequestService {
this.requestService.send(request); this.requestService.send(request);
}); });
return this.fetchRequest(requestId, ...linksToFollow); return endpoint$.pipe(
switchMap(() => this.fetchRequest(requestId, ...linksToFollow)),
);
} }
/** /**
* Factory function to create the request object to send. This needs to be a POST client side and * Factory function to create the request object to send. This needs to be a POST client side and