[SERVER-36715] Pushing $sort stage to query system can leave pipeline in an unstitched state Created: 17/Aug/18  Updated: 29/Oct/23  Resolved: 20/Aug/18

Status: Closed
Project: Core Server
Component/s: Aggregation Framework
Affects Version/s: 4.0.0
Fix Version/s: 4.0.2, 4.1.3

Type: Bug Priority: Critical - P2
Reporter: Nicholas Zolnierz Assignee: Nicholas Zolnierz
Resolution: Fixed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Duplicate
is duplicated by SERVER-40206 Segmentation fault after aggregation ... Closed
Related
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v4.0
Sprint: Query 2018-08-27
Participants:

 Description   

When preparing a plan executor to be used by an aggregation pipeline, there's an optimization here that pushes a $sort stage down to the query system. However, this can result in a pipeline that is not correctly stitched since there may be an additional stage after the sort that is now pointing to free'd memory.



 Comments   
Comment by Githook User [ 20/Aug/18 ]

Author:

{'name': 'Nick Zolnierz', 'email': 'nicholas.zolnierz@mongodb.com', 'username': 'nzolnierzmdb'}

Message: SERVER-36715: Pushing $sort stage to query system can leave pipeline in an unstitched state

(cherry picked from commit 6c2523f7d828ca17a7c175bf82a558bd5bfb57fa)
Branch: v4.0
https://github.com/mongodb/mongo/commit/77ab53420058f9fb58e9bba113f6d7e617068c8b

Comment by Githook User [ 20/Aug/18 ]

Author:

{'name': 'Nick Zolnierz', 'email': 'nicholas.zolnierz@mongodb.com', 'username': 'nzolnierzmdb'}

Message: SERVER-36715: Pushing $sort stage to query system can leave pipeline in an unstitched state
Branch: master
https://github.com/mongodb/mongo/commit/6c2523f7d828ca17a7c175bf82a558bd5bfb57fa

Comment by Ramon Fernandez Marina [ 17/Aug/18 ]

Thanks for the clarification nicholas.zolnierz.

Comment by Nicholas Zolnierz [ 17/Aug/18 ]

ramon.fernandez the optimization that I pointed to in the description was really just exposing the bug. The actual regression was introduced in 4.0 from this commit: https://github.com/mongodb/mongo/commit/b5a2cc0fec6ac30b1a0196da5feb41d85a8b76c3

Comment by David Storch [ 17/Aug/18 ]

Nice work tracking this down, Nick! As discussed in person, we plan to fix this by reintroducing the missing call to Pipeline::optimizePipeline(), which will also be responsible for restitching the Pipeline.

Generated at Thu Feb 08 04:43:53 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.