Open hitigon opened 9 years ago
I found that qt events are still running after the main frame has been loaded, when the Python is ready for exiting, processEvents
is sending requests to somewhere. This causes the segment fault on exit. Not familiar with QT, any suggests?
update: I may not be quite right about processEvents
, but there is something still running in the Qt application. I use os._exit(0) to force the program to quit to fix this problem for now.
I see the same stuff quite frequently. Unfortunately it seems to be in WebKit itself, not in any of the Python libs. Also I can't find any constant pattern - some sites crash on the first run, then they pass OK on the second run.
@kravietz Could you paste few links that chrash? Are you also running osX?
@kravietz You are right, after running my program for almost one month, the crashes were most likely random.
Nope, it's crashing on Linux. Sample:
DEBUG 2014-11-29 14:02:18,580 tasks Worker luxemburg fetching URL http://www.aleqt.com/2014/11/28/article_910177.html date fetched 2014-11-29 14:02:18.566997+00:00
Fatal Python error: Segmentation fault
Current thread 0x00007fe8a316a740 (most recent call first):
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/Ghost.py-0.1b3-py2.7.egg/ghost/ghost.py", line 911 in wait_for
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/Ghost.py-0.1b3-py2.7.egg/ghost/ghost.py", line 928 in wait_for_page_loaded
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/Ghost.py-0.1b3-py2.7.egg/ghost/ghost.py", line 689 in open
File "/home/webcookies/wps2/register_site/tasks.py", line 252 in FetchWebsite
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/celery/app/trace.py", line 438 in __protected_call__
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/celery/app/trace.py", line 240 in trace_task
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/celery/app/trace.py", line 349 in _fast_trace_task
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/billiard/pool.py", line 361 in workloop
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/billiard/pool.py", line 289 in run
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/billiard/process.py", line 292 in _bootstrap
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/billiard/forking.py", line 464 in main
File "<string>", line 1 in <module>
^[[1;31m[2014-11-29 14:02:25,542: ERROR/MainProcess] Process 'Worker-374' pid:32542 exited with 'signal 11 (SIGSEGV)'^[[0m
^[[1;31m[2014-11-29 14:02:25,563: ERROR/MainProcess] Task register_site.tasks.FetchWebsite[cff1ee3d-89ed-480d-b9c6-e6717c91a1a2] raised unexpected: WorkerLostError('Worker exited prematurely: signal 11 (SIGSEGV).',)
Traceback (most recent call last):
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/billiard/pool.py", line 1169, in mark_as_worker_lost
human_status(exitcode)),
WorkerLostError: Worker exited prematurely: signal 11 (SIGSEGV).
And then testing the same in command line:
$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56)
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from ghost import Ghost
>>> g=Ghost()
>>> g.open('http://www.aleqt.com/2014/11/28/article_910177.html')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/Ghost.py-0.1b4-py2.7.egg/ghost/ghost.py", line 689, in open
return self.wait_for_page_loaded()
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/Ghost.py-0.1b4-py2.7.egg/ghost/ghost.py", line 928, in wait_for_page_loaded
'Unable to load requested page')
File "/home/webcookies/wps2/local/lib/python2.7/site-packages/Ghost.py-0.1b4-py2.7.egg/ghost/ghost.py", line 909, in wait_for
raise TimeoutError(timeout_message)
ghost.ghost.TimeoutError: Unable to load requested page
>>> g.open('http://www.aleqt.com/2014/11/28/article_910177.html')
Segmentation fault (core dumped)
(wps2)kravietz@luxemburg:/home/webcookies/wps2$ curl -s http://www.aleqt.com/2014/11/28/article_910177.html | wc -l
1767
Kernel says:
[20061.210061] traps: python[23202] general protection ip:7fa2a1e09787 sp:7fffd9c73db0 error:0 in libQtWebKit.so.4.10.2[7fa2a092a000+1fc9000]
Actually, this particular page seems to be a good target for testing - out of 3 attempts one time it loaded OK, and twice it crashed with segmentationi fault...
Actually, I think I've found it:
#0 0x00007fcf592fa787 in QtMIMETypeSniffer::~QtMIMETypeSniffer() () from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#1 0x00007fcf582d0a0c in WebCore::JSNodeOwner::isReachableFromOpaqueRoots(JSC::Handle<JSC::Unknown>, void*, JSC::SlotVisitor&) () from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#2 0x00007fcf593fbfea in JSC::WeakBlock::visit(JSC::HeapRootVisitor&) () from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#3 0x00007fcf5940d4ab in JSC::MarkedSpace::visitWeakSets(JSC::HeapRootVisitor&) ()
from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#4 0x00007fcf593ff086 in JSC::Heap::markRoots(bool) () from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#5 0x00007fcf59403e85 in JSC::Heap::collect(JSC::Heap::SweepToggle) () from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#6 0x00007fcf595f2492 in JSC::DefaultGCActivityCallback::doWork() () from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#7 0x00007fcf594071b9 in JSC::HeapTimer::timerEvent(QTimerEvent*) () from /usr/lib/x86_64-linux-gnu/libQtWebKit.so.4
#8 0x00007fcf5fe1ca31 in QObject::event(QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#9 0x00007fcf5d6c4e2c in QApplicationPrivate::notify_helper(QObject*, QEvent*) ()
from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#10 0x00007fcf5d6cb4a0 in QApplication::notify(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#11 0x00007fcf5e396c5e in ?? () from /usr/lib/python2.7/dist-packages/PySide/QtGui.so
#12 0x00007fcf5fe044dd in QCoreApplication::notifyInternal(QObject*, QEvent*) () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#13 0x00007fcf5fe34323 in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#14 0x00007fcf5fe315f1 in ?? () from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#15 0x00007fcf5f4a4e04 in g_main_context_dispatch () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#16 0x00007fcf5f4a5048 in ?? () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#17 0x00007fcf5f4a50ec in g_main_context_iteration () from /lib/x86_64-linux-gnu/libglib-2.0.so.0
#18 0x00007fcf5fe317a1 in QEventDispatcherGlib::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#19 0x00007fcf5d766bb6 in ?? () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#20 0x00007fcf5fe0801f in QCoreApplication::processEvents(QFlags<QEventLoop::ProcessEventsFlag>) ()
from /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#21 0x00007fcf60bc72c2 in ?? () from /usr/lib/python2.7/dist-packages/PySide/QtCore.so
#22 0x000000000052c6d5 in PyEval_EvalFrameEx ()
#23 0x000000000052cf32 in PyEval_EvalFrameEx ()
#24 0x000000000055c594 in PyEval_EvalCodeEx ()
#25 0x000000000052ca8d in PyEval_EvalFrameEx ()
#26 0x000000000055c594 in PyEval_EvalCodeEx ()
#27 0x000000000052ca8d in PyEval_EvalFrameEx ()
#28 0x000000000055c594 in PyEval_EvalCodeEx ()
#29 0x00000000005b7392 in PyEval_EvalCode ()
Will file a bug with WebKit for that.
@kravietz @hitigon Looks like you're running "outdated" ghosts, you should upgrade as https://github.com/jeanphix/Ghost.py/commit/3044c63e10a3ee3b239c68c93b80a55143784259 from 0.1b5
fixes lot of issues related to cache.
I am also troubled with the core. For some pages, it always causes core dumping during page loading.
at libc-start.c:287
(gdb) info threads Id Target Id Frame 7 Thread 0x7f708bfff700 (LWP 30545) 0x00007f70e4634c6d in poll () at ../sysdeps/unix/syscall-template.S:81 6 Thread 0x7f708ade2700 (LWP 30548) 0x00007f70e46398e3 in select () at ../sysdeps/unix/syscall-template.S:81 5 Thread 0x7f70916d0700 (LWP 30544) 0x00007f70e4634c6d in poll () at ../sysdeps/unix/syscall-template.S:81 4 Thread 0x7f708b7fe700 (LWP 30546) pthread_cond_timedwait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_timedwait.S:238 3 Thread 0x7f7092426700 (LWP 30543) pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185 2 Thread 0x7f70d4286700 (LWP 30541) pthread_cond_wait@@GLIBC_2.3.2 () at ../nptl/sysdeps/unix/sysv/linux/x86_64/pthread_cond_wait.S:185
OK, I think I found the core-dumping case: When the page uses following HTML elements, it cause segment faults
the direct way to avoid them is to disable them
@HarryQian commented on 22 дек. 2014 г., 7:52 GMT+3:
OK, I think I found the core-dumping case:
When the page uses following HTML elements, it cause segment faults
- localStorage or sessionStorage
- websocket
the direct way to avoid them is to disable them
But how do this? A can't find anything about disabling features in documentation.
Now I am using PY-QT 5, it’s more efficient and really gets seldom core dump. so better update to new version.
I have Debian Wheezy on my servers... Installing Qt5 also update big part of system... Not good way.
Harry: ghost doesnt work with qt5, just qt4.
@petermat Actually it does, with this small patch https://github.com/jeanphix/Ghost.py/pull/205 and you will also need Python3 as there's no PyQt5 for Python2 (at least not in Ubuntu). But it works suprisingly well:
Python 3.4.0 (default, Jun 19 2015, 14:20:21)
[GCC 4.8.2] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> from ghost import Ghost
>>> g=Ghost()
>>> g.open('https://ipsec.pl/')
(<ghost.ghost.HttpResource object at 0x7fdb723f2400>, ...
Unfortunately, this fatal test site http://www.aleqt.com/2014/11/28/article_910177.html still causes a crash inside Qt5 libraries :(
It keeps crashing randomly even on v0.2 ... Notably, the log
[WARNING ] QT: QFont::setPixelSize: Pixel size <= 0 (0)
seems to always precede the crash
settting session.page = None fixes it for me
from ghost import Ghost
gho = Ghost()
with gho.start() as session:
page, extra_resources = session.open("https://ipsec.pl/")
assert page.http_status == 200
session.page = None
for me help
webkit=Ghost()
webkit.evaluate('window.WebSockets=undefined')
webkit.evaluate('window.localStorage=undefined')
webkit.evaluate('window.sessionStorage=undefined')
webkit.evaluate('window.RTCPeerConnection=undefined')
webkit.evaluate('window.webkitRTCPeerConnection=undefined')
webkit.evaluate('window.mozRTCPeerConnection=undefined')
@Brainback if page is set to None, it will lead to a memory leak in the program. the memory will exhaust.
I got the same problem. I pulled the docker image named ghost-py. The image have already installed python2.7 and pyside. I added ghost0.2.3. The docker runs on 64 bit ubuntu14.04. The same code ran on win7 with pyqt4 installed works well,but when ran in docker,it exited silently sometimes and I didn't catch any exception. Finally I found that the exception was "segmentation fault" or "qt - WARNING - ghost: Fatal IO error: client killed". If you solved the problem,please let me know.
The real reason for having this bug is that you're using nonpatched qtwebkit. Try out the one from 2.3.2-0ubuntu9 (Ubuntu 16.04 or newer) and it should go away.
@d33tah please consider giving a try at this branch (PySide2, Qt5): https://github.com/jeanphix/ghost.py/tree/pyside2
Cheers,
@jeanphix TBH this bug is not affecting me, it's just number one in Google search for this segfault. I wanted to let others know because I had the same problem in another application using qtwebkit.
@d33tah Sure, just I'd be happy to get feedback about the upcoming stuff :)
@jeanphix I'm running pyside2 and still getting segfaults FYI
@rcoh When does it happen?
It's happening on the session.open call. Here's my flow:
ghost()
with
, wait for a couple of things.Possibly the problem is that I'm opening multiple sessions? Having multiple sessions running at the same time is critical for my use case, however.
@rcoh Can't reproduce it, can you write a tiny failing script?
Hmm it appears to be related to the specific page I was loading...will have to debug more to figure out what about the page is causing the segfault. Is there anyway to get more of a stack trace?
I think I found the problem.
INFO:ghost.session:Page loaded https://[redacted]
INFO:ghost.session:Closing session
INFO:ghost.session:Resource loaded: https://[redacted] 200
INFO:loadtool:Start action: <_MainThread(MainThread, started 139801505380096)>
INFO:ghost.application:Initializing QT application
INFO:ghost.session:Starting new session
Segmentation fault
It seems like a resource is getting loaded even after the session is closed. When a attempted to open a new session, we get a segfault.
This is fixed if I use a session.sleep()
but it's pretty annoying
INFO:ghost.session:Page loaded https://....
(sleep for 20 seconds)
INFO:ghost.session:Closing session
INFO:ghost.session:Resource loaded: https://...
Although since as a function of this, I can't run concurrent sessions anyway without a segfault, this doesn't really work for me.
@rcoh think it's related to this https://github.com/jeanphix/Ghost.py/pull/319/commits/52f31087c7d08fa7349ec9c55d75ff901be4f446, right ?
ping @EvaSDK
yeah that looks like precisely the issue. Any idea about concurrent sessions?
@rcoh having several sessions living at same time just works well, isn't it?
hmm I got immediate segfaults. Will try to make a reproducer
@jeanphix https://gist.github.com/rcoh/d8c119441f0b2789a36cc3368e1273c0 I'm running that script against the pyside2 branch within the provided docker container.
Completely missed this ping, sorry for this. I merged my network request tracker in ghost-py-0-2 branch this week as I was finally re-assigned to working on this. I am still tracking down some segfaults but it proves difficult.
The program will exit with segmentation faults when loading some pages. But sometimes, these pages may be loaded normally and the program exits normally.
Report: