MCPcopy
hub / github.com/mongodb/node-mongodb-native / processWaitQueue

Method processWaitQueue

src/cmap/connection_pool.ts:724–816  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

722 }
723
724 private processWaitQueue() {
725 if (this.processingWaitQueue) {
726 return;
727 }
728 this.processingWaitQueue = true;
729
730 while (this.waitQueueSize) {
731 const waitQueueMember = this.waitQueue.first();
732 if (!waitQueueMember) {
733 this.waitQueue.shift();
734 continue;
735 }
736
737 if (waitQueueMember.cancelled) {
738 this.waitQueue.shift();
739 continue;
740 }
741
742 if (this.poolState !== PoolState.ready) {
743 const reason = this.closed ? 'poolClosed' : 'connectionError';
744 const error = this.closed ? new PoolClosedError(this) : new PoolClearedError(this);
745 this.emitAndLog(
746 ConnectionPool.CONNECTION_CHECK_OUT_FAILED,
747 new ConnectionCheckOutFailedEvent(this, reason, waitQueueMember.checkoutTime, error)
748 );
749 this.waitQueue.shift();
750 waitQueueMember.reject(error);
751 continue;
752 }
753
754 if (!this.availableConnectionCount) {
755 break;
756 }
757
758 const connection = this.connections.shift();
759 if (!connection) {
760 break;
761 }
762
763 if (!this.destroyConnectionIfPerished(connection)) {
764 this.checkedOut.add(connection);
765 this.emitAndLog(
766 ConnectionPool.CONNECTION_CHECKED_OUT,
767 new ConnectionCheckedOutEvent(this, connection, waitQueueMember.checkoutTime)
768 );
769
770 this.waitQueue.shift();
771 waitQueueMember.resolve(connection);
772 }
773 }
774
775 const { maxPoolSize, maxConnecting } = this.options;
776 while (
777 this.waitQueueSize > 0 &&
778 this.pendingConnectionCount < maxConnecting &&
779 (maxPoolSize === 0 || this.totalConnectionCount < maxPoolSize)
780 ) {
781 const waitQueueMember = this.waitQueue.shift();

Callers 5

checkOutMethod · 0.95
checkInMethod · 0.95
clearMethod · 0.95
closeMethod · 0.95
ensureMinPoolSizeMethod · 0.95

Calls 8

createConnectionMethod · 0.95
firstMethod · 0.80
emitAndLogMethod · 0.80
rejectMethod · 0.80
addMethod · 0.80
shiftMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected