fix: mongodb resolves leaked cursor (#10316)

This change resolves a leaked cursor used to avoid
    a stack overflow during entity transformation.

    Closes: #10315
This commit is contained in:
Corey Shupe 2023-12-29 10:20:49 -05:00 committed by GitHub
parent 3af891a8e6
commit 2dc9624d00
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1025,11 +1025,11 @@ export class MongoEntityManager extends EntityManager {
cursor: FindCursor<Entity> | AggregationCursor<Entity>,
) {
const queryRunner = this.mongoQueryRunner
cursor.toArray = () =>
cursor
.clone()
.toArray()
.then(async (results: Entity[]) => {
;(cursor as any)["__to_array_func"] = cursor.toArray
cursor.toArray = async () =>
((cursor as any)["__to_array_func"] as CallableFunction)().then(
async (results: Entity[]) => {
const transformer = new DocumentToEntityTransformer()
const entities = transformer.transformAll(results, metadata)
// broadcast "load" events
@ -1039,13 +1039,12 @@ export class MongoEntityManager extends EntityManager {
entities,
)
return entities
})
cursor.next = () =>
cursor
.clone()
.next()
.then(async (result: Entity) => {
},
)
;(cursor as any)["__next_func"] = cursor.next
cursor.next = async () =>
((cursor as any)["__next_func"] as CallableFunction)().then(
async (result: Entity) => {
if (!result) {
return result
}
@ -1056,7 +1055,8 @@ export class MongoEntityManager extends EntityManager {
entity,
])
return entity
})
},
)
}
protected filterSoftDeleted<Entity>(