Skip to content

Commit 105d32a

Browse files
committed
RDBC-210 fix promise was created but not returned
1 parent ec135d0 commit 105d32a

File tree

1 file changed

+40
-41
lines changed

1 file changed

+40
-41
lines changed

src/Http/RequestExecutor.ts

Lines changed: 40 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as os from "os";
22
import * as BluebirdPromise from "bluebird";
33
import * as semaphore from "semaphore";
44
import * as stream from "readable-stream";
5-
import { acquireSemaphore } from "../Utility/SemaphoreUtil";
5+
import { acquireSemaphore, AcquiredSemaphoreContext } from "../Utility/SemaphoreUtil";
66
import { getLogger, ILogger } from "../Utility/LogUtil";
77
import { Timer } from "../Primitives/Timer";
88
import { ServerNode } from "./ServerNode";
@@ -327,54 +327,53 @@ export class RequestExecutor implements IDisposable {
327327
.then(() => this._nodeSelector.getFastestNode());
328328
}
329329

330-
protected _updateClientConfiguration(): PromiseLike<void> {
331-
if (this._disposed) {
332-
return BluebirdPromise.resolve(null);
333-
}
330+
private async _updateClientConfigurationInternal(): Promise<void> {
331+
const oldDisableClientConfigurationUpdates = this._disableClientConfigurationUpdates;
332+
this._disableClientConfigurationUpdates = true;
334333

335-
const updateClientConfigurationInternal = () => {
336-
const oldDisableClientConfigurationUpdates = this._disableClientConfigurationUpdates;
337-
this._disableClientConfigurationUpdates = true;
334+
try {
335+
if (this._disposed) {
336+
return;
337+
}
338338

339-
return BluebirdPromise.resolve()
340-
.then(() => {
339+
const command = new GetClientConfigurationCommand();
340+
const { currentNode, currentIndex } = this.chooseNodeForRequest(command, null);
341+
await this.execute(command, null, {
342+
chosenNode: currentNode,
343+
nodeIndex: currentIndex,
344+
shouldRetry: false
345+
});
341346

342-
if (this._disposed) {
343-
return;
344-
}
347+
const clientConfigOpResult = command.result;
348+
if (!clientConfigOpResult) {
349+
return;
350+
}
345351

346-
const command = new GetClientConfigurationCommand();
347-
const currentIndexAndNode2: CurrentIndexAndNode = this.chooseNodeForRequest(command, null);
348-
return this.execute(command, null, {
349-
chosenNode: currentIndexAndNode2.currentNode,
350-
nodeIndex: currentIndexAndNode2.currentIndex,
351-
shouldRetry: false
352-
})
353-
.then(() => command.result);
354-
})
355-
.then((clientConfigOpResult: GetClientConfigurationOperationResult) => {
356-
if (!clientConfigOpResult) {
357-
return;
358-
}
352+
this._conventions.updateFrom(clientConfigOpResult.configuration);
353+
this._clientConfigurationEtag = clientConfigOpResult.etag;
354+
} catch (err) {
355+
this._log.error(err, "Error getting client configuration.");
356+
} finally {
357+
this._disableClientConfigurationUpdates = oldDisableClientConfigurationUpdates;
358+
}
359+
}
359360

360-
this._conventions.updateFrom(clientConfigOpResult.configuration);
361-
this._clientConfigurationEtag = clientConfigOpResult.etag;
361+
protected async _updateClientConfiguration(): Promise<void> {
362+
if (this._disposed) {
363+
return;
364+
}
362365

363-
})
364-
.tapCatch(err => this._log.error(err, "Error getting client configuration."))
365-
.finally(() => {
366-
this._disableClientConfigurationUpdates = oldDisableClientConfigurationUpdates;
367-
});
368-
};
366+
let semAcquiredContext: AcquiredSemaphoreContext;
369367

370-
const semAcquiredContext = acquireSemaphore(this._updateClientConfigurationSemaphore);
371-
const result = BluebirdPromise.resolve(semAcquiredContext.promise)
372-
.then(() => updateClientConfigurationInternal())
373-
.finally(() => {
368+
try {
369+
semAcquiredContext = acquireSemaphore(this._updateClientConfigurationSemaphore);
370+
await semAcquiredContext.promise;
371+
await this._updateClientConfigurationInternal();
372+
} finally {
373+
if (semAcquiredContext) {
374374
semAcquiredContext.dispose();
375-
});
376-
377-
return Promise.resolve(result);
375+
}
376+
}
378377
}
379378

380379
public updateTopology(node: ServerNode, timeout: number, forceUpdate: boolean = false): Promise<boolean> {

0 commit comments

Comments
 (0)