Bug 131078 - some Web worker threads never terminate
Summary: some Web worker threads never terminate
Status: ASSIGNED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebCore Misc. (show other bugs)
Version: 528+ (Nightly build)
Hardware: All Unspecified
: P2 Major
Assignee: Mark Lam
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2014-04-01 16:27 PDT by abaldeva
Modified: 2015-07-29 19:24 PDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description abaldeva 2014-04-01 16:27:17 PDT
Hi,

If a web worker is executing a javascript in a while(true){..} loop, the OS Worker thread created for it never terminates. An example can be seen here - http://www.whatwg.org/demos/workers/primes/page.html 

The watchdog mechanism starts out as disabled. This means that timeout JIT::emit_op_loop_hint in JITOpcodes.cpp never emits the timeout check mechanism. Thus, when the web worker is expected to terminate (either by explicitly calling worker.terminate() or moving away from the page), execution never comes out of script->evaluate in WorkerThread::workerThread(). This results in the OS thread hanging around. 

The C Loop interpreter backend has the same issue except that it ends up waiting on m_timerDidFire in watchdog which never turns true. 

--Arpit
Comment 1 abaldeva 2014-04-01 16:41:04 PDT
One possible solution to this problem might be to start VM watchdog timer with a small timeout value (1-2 sec? )and a callback (using Watchdog::setTimeLimit API). This will force the script execution to check the WorkerScriptController regularly. The callback keeps returning false unless the WorkerScriptController::scheduleExecutionTermination has been called.

--Arpit
Comment 2 Mark Lam 2015-07-29 19:04:27 PDT
I’ve confirmed that m_didFire is indeed not reset.  Let me think about what the right thing to do is, and implement a fix.
Comment 3 Mark Lam 2015-07-29 19:24:26 PDT
(In reply to comment #2)
> I’ve confirmed that m_didFire is indeed not reset.  Let me think about what
> the right thing to do is, and implement a fix.

Oops.  Commented in wrong bug.  Please disregard.