Skip to content
Merged
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
12 changes: 6 additions & 6 deletions apps/provider-proxy/src/services/WebsocketServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ export class WebsocketServer {
const pws = this.connectWebSocket(url, options);

this.openProviderSockets[options.wsId] = { ws: pws, verification: "in-progress" };
const wsDetails = this.openProviderSockets[options.wsId];

pws.on(
"upgrade",
Expand All @@ -270,7 +271,7 @@ export class WebsocketServer {
const socket = response.socket && response.socket instanceof TLSSocket ? response.socket : undefined;
if (socket?.authorized) {
// CA validation is successful, so certificate is not self-signed
this.openProviderSockets[options.wsId].verification = "finished";
wsDetails.verification = "finished";
pws.emit("verified");
return;
}
Expand Down Expand Up @@ -307,7 +308,7 @@ export class WebsocketServer {
pws.removeAllListeners("message");
pws.removeAllListeners("verified");

this.openProviderSockets[options.wsId].verification = "failed";
wsDetails.verification = "failed";
pws.close(WS_ERRORS.VIOLATED_POLICY, `invalidCertificate.${result.code}`);
this.logger?.warn({
event: "PROVIDER_INVALID_CERTIFICATE",
Expand All @@ -317,9 +318,8 @@ export class WebsocketServer {
providerAddress: options.providerAddress
});
} else {
// ensure that socket was not closed while its certificate was validating
if (pws.readyState === WebSocket.OPEN && this.openProviderSockets[options.wsId]) {
this.openProviderSockets[options.wsId].verification = "finished";
if (pws.readyState === WebSocket.OPEN && Object.hasOwn(this.openProviderSockets, options.wsId)) {
wsDetails.verification = "finished";
pws.emit("verified");
this.logger?.debug({
event: "PROVIDER_CERTIFICATE_VERIFIED",
Expand All @@ -344,7 +344,7 @@ export class WebsocketServer {
})
);

return this.openProviderSockets[options.wsId];
return wsDetails;
}

private connectWebSocket(url: string, options: CreateProviderSocketOptions) {
Expand Down