mirror of
https://github.com/typeorm/typeorm.git
synced 2025-12-08 21:26:23 +00:00
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:
parent
3af891a8e6
commit
2dc9624d00
@ -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>(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user