finding concurrency errors in event-driven applications - strangeloop'14

25
EventRacer: Finding Concurrency Errors in Event-Driven Applications Pavol Bielik

Upload: pavol-bielik

Post on 13-Dec-2014

134 views

Category:

Software


1 download

DESCRIPTION

We present a new open-source analysis system called EventRacer (www.eventracer.org) developed at the Software Reliability Lab at ETH Zurich, that finds harmful concurrency errors in event-driven applications such as web pages and Android applications. We illustrate how these concurrency errors can occur in real-world applications as well as the key analysis mechanisms behind EventRacer.

TRANSCRIPT

Page 1: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

EventRacer: Finding Concurrency Errors in Event-Driven Applications

Pavol Bielik

Page 2: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

Android Errors Caused by Concurrency

Display article twice Display wrong directory Display wrong order Rate wrong card

1

Page 3: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

Web Page Errors Caused by Concurrency

Incomplete form submitted Non-operational menu

jQuery version used non-deterministically

2

Page 4: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

designed to hide latency, various asynchronous APIsnetwork, disk, database, timers, UI events

highly asynchronous and complex control flowscheduling non-determinism

asynchrony is not intuitive

Event-Driven Applications

3

Page 5: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

Trouble with Asynchrony

Background task, progress dialog, orientation change - is there any 100% working solution?

Is AsyncTask really conceptually flawed or am I just missing something?

Ajax Call Sometimes Works, Sometime works and refreshes, Sometimes refreshes and fails …?

Avoiding race conditions in Google Analytics asynchronous tracking

JavaScript function sometimes called, sometimes not

4

Page 6: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

<html><body>

<script>

var v=undefined;

</script>

<img src="img1.png" onload="v='Hi!';">

<img src="img2.png" onload="alert(v);">

</body></html>

“Hello World” of web page concurrency

Browser Server

fetch img1.png

fetch img2.png

load img1.png

load img2.png

v:undefined

v:’Hi!’

Hi!

5

Page 7: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

<html><body>

<script>

var v=undefined;

</script>

<img src="img1.png" onload="v='Hi!';">

<img src="img2.png" onload="alert(v);">

</body></html>

Bad interleaving

Browser Server

fetch img1.png

fetch img2.png

load img2.png

v:undefined

undefined

5

Page 8: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

<html><body>

<script>

var v=undefined;

</script>

<img src=”img1.png” onload=”v=’Hi!’;”>

<img src=”img2.png” onload=”alert(v);”>

</body></html>

Understanding the problem

Event Actions

6

Page 9: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

<html><body>

<script>

var v=undefined;

</script>

<img src=”img1.png” onload=”v=’Hi!’;”>

<img src=”img2.png” onload=”alert(v);”>

</body></html>

Understanding the problem

Event Actions

Happens-before

6

Page 10: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

<html><body>

<script>

var v=undefined;

</script>

<img src=”img1.png” onload=”v=’Hi!’;”>

<img src=”img2.png” onload=”alert(v);”>

</body></html>

Understanding the problem

Racewrite v

read v

Event Actions

Happens-before

6

Page 11: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

Online Analysishttp://www.eventracer.org

7

Page 12: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

EventRacer end-to-end SystemInstrumented

SystemExecution

TraceHappens-before

GraphRace

Detector?

?

?

Race Explorer

Race Filtering and Grouping

Android App,Web Page

7

Page 13: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

EventRacer end-to-end System

<img id="img1" src="img1.png"

onload="v='Hi!';">

<script>

document.getElementById("img1")

.addEventListener("click", f);

</script>

↦ write(#img1)

↦ write(#img1.onload)

↦ read(#img1)

↦ write(#img1.click)

DOM nodes and attributes

<script>

v='Hi!';

function f() {}

messages[2] = 42;

</script>

↦ write(v)

↦ write(f)

↦ write(messages[2])

JS variables, functions, arrays

What are the memory locations on which asynchronous events can race?

InstrumentedSystem

ExecutionTrace

Happens-beforeGraph

Race Detector

?

?

?

Race Explorer

Race Filtering and Grouping

Android App,Web Page

8

Page 14: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

EventRacer end-to-end System

Web - parsing an HTML element - executing a script - handling user input - ...

<script>

var v=undefined;

</script>

<img src=”img1.png” onload=”v=’Hi!’;”>

<img src=”img2.png” onload=”alert(v);”>

What are the atomic events used in event-driven applications?

InstrumentedSystem

ExecutionTrace

Happens-beforeGraph

Race Detector

?

?

?

Race Explorer

Race Filtering and Grouping

Android App,Web Page

9

Page 15: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

EventRacer end-to-end System

<script>

var v=undefined;

</script>

<img src=”img1.png” onload=”v=’Hi!’;”>

<img src=”img2.png” onload=”alert(v);”>

Happens-before

What is the event happens-before?

WebsetInterval, SetTimeout, AJAX, …

AndroidpostDelayed, postAtFront, postIdle, ...

InstrumentedSystem

ExecutionTrace

Happens-beforeGraph

Race Detector

?

?

?

Race Explorer

Race Filtering and Grouping

Android App,Web Page

10

Page 16: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

EventRacer end-to-end System

<script>

var v=undefined;

</script>

<img src=”img1.png” onload=”v=’Hi!’;”>

<img src=”img2.png” onload=”alert(v);”>

Racewrite v

read v

How to make scalable race detection in event-based setting? (Naive algorithms have asymptotic complexity O(N3) and require O(N2) space)

State of the art EventRacer

runtime TIMEOUT 2.4sec

memory 25181MB 171MB

InstrumentedSystem

ExecutionTrace

Happens-beforeGraph

Race Detector

?

?

?

Race Explorer

Race Filtering and Grouping

Android App,Web Page

11

Page 17: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

EventRacer end-to-end System

Is the system effective at finding harmful races while reporting few benign races?

We filter common classes of benign races:commutative operations, recycled objects, lazy initialization, local reads, ...

Web Android

# races found 646 1328

# races reported 17.3 13

reduction 37x 100x

InstrumentedSystem

ExecutionTrace

Happens-beforeGraph

Race Detector

?

?

?

Race Explorer

Race Filtering and Grouping

Android App,Web Page

13

Page 18: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

Manual evaluation

synchronization racesvarious idioms:✓ if (ready) …✓ try { … } catch { retry }✓ array of callbacks✓ etc.

harmless races✓ commutative

operations✓ benign races✓ framework related

Harmful bugs✓ unhandled exceptions✓ UI glitches✓ broken analytics✓ page needs refresh to

work normally

Web (314 reports)Fortune 100 Web Pages

Android (104 reports)8 Play Store Applications

14

24.6%

58.4%

17% 57.7%

17.3%

25%

Page 19: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

protected void onCreate() {

locationManager.requestLocationUpdates(GPS_PROVIDER, 0, 0, mListener);

mDbHelper = new SQLiteOpenHelper(this, DB_NAME, DB_VERSION);

}

LocationListener mListener = new LocationListener() {

public void onLocationChanged(Location location) {

//show location on map

mDbHelper.getWritableDatabase().insert(loc);

} };

protected void onStop() {

locationManager.removeUpdates(mListener);

mDbHelper.close();

}

Simple GPS Tracker

15

Page 20: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

protected void onCreate() {

locationManager.requestLocationUpdates(GPS_PROVIDER, 0, 0, mListener);

mDbHelper = new SQLiteOpenHelper(this, DB_NAME, DB_VERSION);

}

LocationListener mListener = new LocationListener() {

public void onLocationChanged(Location location) {

//show location on map

mDbHelper.getWritableDatabase().insert(loc);

} };

protected void onStop() {

locationManager.removeUpdates(mListener);

mDbHelper.close();

}

Simple GPS Tracker

15

protected void onStop() {

locationManager.removeUpdates(mListener);

mDbHelper.close();

}

public void removeUpdates (LocationListener listener)

Added in API level 1

Removes all location updates for the specified LocationListener.Following this call, updates will no longer occur for this listener.

Page 21: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

http://www.eventracer.org/android

16

Page 22: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

event 1 sourceasync IPC, interface(android.location.ILocationListener),code(onLocationChanged))

event 2 sourceasync IPC, interface(android.app.IApplicationThread), code(SCHEDULE_STOP_ACTIVITY))

→calling context Landroid/database/sqlite/SQLiteDatabase;.insert(...)

→calling context Landroid/database/sqlite/SQLiteClosable;.close(...)

→ UPDATE-UPDATE - 63568 Landroid/database/sqlite/SQLiteConnectionPool;.mAvailablePrimaryConnection → READ-UPDATE - 63568 Landroid/database/sqlite/SQLiteConnectionPool;.mIsOpen → READ-UPDATE - 63576 Landroid/database/sqlite/SQLiteConnection;.mConnectionPtr → READ-UPDATE - 63576 Landroid/database/sqlite/SQLiteConnection;.mPreparedStatementPool

Analysis Results

onLocationChanged and onStop are reported as not ordered

16

Page 23: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

Is the Alternative Interleaving Feasible?D/GPS: onCreateD/GPS: insert: Location[gps 47.284646,8.632389 acc=10 et=0 vel=2.0 mock]D/GPS: insert: Location[gps 47.284656,8.632598 acc=10 et=0 vel=2.0 mock]D/GPS: insert: Location[gps 47.284712,8.632722 acc=10 et=0 vel=2.0 mock]D/GPS: insert: Location[gps 47.284832,8.632837 acc=10 et=0 vel=2.0 mock]D/GPS: onStopD/GPS: insert: Location[gps 47.285022,8.633205 acc=10 et=0 vel=2.0 mock]

E/AndroidRuntime: FATAL EXCEPTION: mainE/AndroidRuntime: Process: com.example.gps, PID: 2249E/AndroidRuntime: java.lang.IllegalStateException: attempt to re-open an already-closed object: SQLiteDatabase: /data/data/com.example.gps/test.db

16

Page 24: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

Google Chromium portV8 javascript engine instrumentation

Testing tools based on EventRacerIntegration with SeleniumPhantomJS

Application for Parallelization

Other Application Domains (beyond Web Pages, Android)Node.js

Current Directions

17

Page 25: Finding Concurrency Errors in Event-Driven Applications - Strangeloop'14

Martin Vechev, Veselin Raychev, Pavol Bielik

Anders Møller, Casper Jensen

Manu Sridharan

Boris Petrov, Yasen Trifonov

Julian Dolby

www.eventracer.orgwww.eventracer.org/android

InstrumentedSystem

ExecutionTrace

Happens-beforeGraph

Race Detector

?

?

?

Race Explorer

Race Filtering and Grouping

Android App,Web Page