Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Work around for mongo driver bug 722 #138

Closed
wants to merge 1 commit into from
Closed

Work around for mongo driver bug 722 #138

wants to merge 1 commit into from

Conversation

superdweebie
Copy link

No description provided.

@jmikola
Copy link
Member

jmikola commented Oct 4, 2013

Unfortunately, this isn't an all-purpose work-around. When @bjori suggested this in PHP-722, the context was that the user had a reproducible point in their code where the segfault was triggered by the internal argument stack filling up. Creating a NOP method call forced PHP to expand the stack, but that was very dependent on the code leading up to that point. Instead of three arguments, four or five might have been necessary.

Doctrine is not going to be a suitable place for any work-around code, since its find() method could be called from any application context. Also, this isn't just a problem with find() -- any driver function that is using the legacy macros to chain to other driver PHP methods are at risk.

@superdweebie
Copy link
Author

:(

I was getting strange errors on deep stacks which matched the description of PHP-722. Adding this appeared to fix the problem.

Do you have any other suggestions?

@jmikola
Copy link
Member

jmikola commented Oct 5, 2013

@superdweebie: If the errors are appearing at the same point in your application, the most reliable work-around will be to call the NOP function before interacting with Doctrine. Technical explanation follows:

I was talking to @bjori about this last night and suggested using a NOP function with dozens of arguments (or more) to force argument stack growth. After it returned, I expected the stack would then shrink again after the function returned -- so a perfect work-around would just be to use enough arguments for all of the internal MONGO_METHOD() calls in our driver. The NOP function would increase the stack size by X (growing it if necessary), and then if it was freed up, we'd have more than enough space for the MONGO_METHOD() chain.

Unfortunately, after digging through PHP's opcodes a bit, we concluded that the internal stack will never shrink if an assignment operation is happening in a higher calling context (e.g. Symfony assigning the $response object in your root controller). Therefore, a NOP function that doesn't result in growing the argument stack will simply consume space on the existing stack and bring you closer to a segfault! That's why we can't use a general solution for this.


MONGO_METHOD() is the internal macro in our driver that calls other driver object methods through the C driver. This is legacy code dating back to the original driver, which was implemented in PHP, being ported to C and built up from there. For 1.5, we're hoping to get rid of these macros entirely -- it's a big refactoring task. When I refer to the argument stack above, that's PHP's internal stack for userland PHP arguments, which MONGO_METHOD() unfortunately utilizes (albeit without the ability to properly grow the stack).

@superdweebie
Copy link
Author

@jmikola thanks for the great explination. I will just have to wait for the next mongo diver version for a robust fix.

@jmikola
Copy link
Member

jmikola commented Jul 30, 2014

@superdweebie: The stack error has been fixed in driver version 1.5.5 (see: PHP-722).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants