facebook / hhvm

A virtual machine for executing programs written in Hack.
https://hhvm.com
Other
18.15k stars 2.99k forks source link

DOMNodeList string conversion Fatal error #2617

Closed kientran closed 10 years ago

kientran commented 10 years ago

I've gotten this particular error in the past, but it's become very frequent as of late.

\nFatal error: Object of class DOMNodeList could not be converted to string in /var/www/dev.kientran.com/wp-content/themes/enfold/config-layerslider/LayerSlider/helpers/phpQuery.php on line 659

A very specific plugin as part of my wordpress theme is obviously crashing. This plugin is using an older php addin from 2009. http://code.google.com/p/phpquery/

When the service crashes, nothing ends up getting returned by HHVM and HHVM must be restarted.

The CRAZY part is that it works for a while, then suddenly stops working. Weirdly, until recently, it had worked fine since 3.0 was released, when I installed HHVM. In the last week, it's been frequently crashing out.

HHVM-dbg doesn't return anything when it errors out, but I may just not be looking in the right place or in the right way.

Interestingly, this does not affect other virtual hosts on the same machine. They continue to operate without issue.

The related function is as follows. It crashes at $noBody = strpos($markup, '<body') === false;

private function documentFragmentLoadMarkup($fragment, $charset, $markup = null) {
                // TODO error handling
                // TODO copy doctype
                // tempolary turn off
                $fragment->isDocumentFragment = false;
                if ($fragment->isXML) {
                        if ($fragment->isXHTML) {
                                // add FAKE element to set default namespace
                                $fragment->loadMarkupXML('<?xml version="1.0" encoding="'.$charset.'"?>'
                                        .'<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" '
                                        .'"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'
                                        .'<fake xmlns="http://www.w3.org/1999/xhtml">'.$markup.'</fake>');
                                $fragment->root = $fragment->document->firstChild->nextSibling;
                        } else {
                                $fragment->loadMarkupXML('<?xml version="1.0" encoding="'.$charset.'"?><fake>'.$markup.'</fake>');
                                $fragment->root = $fragment->document->firstChild;
                        }
                } else {
                        $markup2 = phpQuery::$defaultDoctype.'<html><head><meta http-equiv="Content-Type" content="text/html;charset='
                                .$charset.'"></head>';
                        $noBody = strpos($markup, '<body') === false;
                        if ($noBody)
                                $markup2 .= '<body>';
                        $markup2 .= $markup;
                        if ($noBody)
                                $markup2 .= '</body>';
                        $markup2 .= '</html>';
                        $fragment->loadMarkupHTML($markup2);
                        // TODO resolv body tag merging issue
                        $fragment->root = $noBody
                                ? $fragment->document->firstChild->nextSibling->firstChild->nextSibling
                                : $fragment->document->firstChild->nextSibling->firstChild->nextSibling;
                }
                if (! $fragment->root)
                        return false;
                $fragment->isDocumentFragment = true;
                return true;
        }
SiebelsTim commented 10 years ago

You say it crashes sometimes. Does this also happen with -vEval.Jit=0?

kientran commented 10 years ago

I restarted hhvm with vEval.Jit=0 and it seems to have fixed the problem. I repeated loaded the page without incident via AB testing and directly loading it in browser.

Running without it will result in a crash for that page's after a few reloads. I'm guessing something goes wrong with the cached bytecode? What can I do to help you guys look deeper into the issue?

On Tue, May 6, 2014 at 9:24 AM, SiebelsTim notifications@github.com wrote:

You say it crashes sometimes. Does this also happen with -vEval.Jit=0?

— Reply to this email directly or view it on GitHubhttps://github.com/facebook/hhvm/issues/2617#issuecomment-42308240 .

Kien Tran http://kientran.me

SiebelsTim commented 10 years ago

So it can be narrowed down to an issue with the JIT.

Default value for warmupRequests is 11. That's why it breaks your 12th request. The first 11 requests are in interpreter only mode.

kientran commented 10 years ago

That seems consistent with this particular issue. It's most noticeable when the site gets loaded frequently in a short time period. Are there some debugging stacks I can generate to help narrow down the issues?

On Tue, May 6, 2014 at 12:32 PM, SiebelsTim notifications@github.comwrote:

So it can be narrowed down to an issue with the JIT.

Default value for warmupRequests is 11. That's why it breaks your 12th request. The first 11 requests are in interpreter only mode.

— Reply to this email directly or view it on GitHubhttps://github.com/facebook/hhvm/issues/2617#issuecomment-42333220 .

Kien Tran http://kientran.me

fredemmott commented 10 years ago

Is HHVM itself crashing, or just emitting a fatal error? If it's crashing, try running it in gdb and getting a backtrace.

kientran commented 10 years ago

HHVM is not crashing. It's just a Fatal error. The error applies to any page code that uses that particular function out of the cache. Other sites on the same machine or pages on the same site that don't access that particular plugin continue to work.

On Thu, May 15, 2014 at 5:05 PM, Fred Emmott notifications@github.comwrote:

Is HHVM itself crashing, or just emitting a fatal error? If it's crashing, try running it in gdb and getting a backtrace.

— Reply to this email directly or view it on GitHubhttps://github.com/facebook/hhvm/issues/2617#issuecomment-43270890 .

Kien Tran http://kientran.me

LiraNuna commented 10 years ago

This is a runtime error, not a crash. I doubt the issue is that - the function that calls documentFragmentLoadMarkup is probably giving it a DOMNodeList instead of what appears to be a string.

lbadger commented 10 years ago

I am currently experiencing the same issue. Any update on this?

kientran commented 10 years ago

HHVM 3.1 corrects whatever this issue was... I've not had any issues since updating.