Personal tools
You are here: Home Data Concurrency bug patterns Case6

Case6

A long HTML content makes parsing stop at unsafe point

Description

Browsers pause parsing if the contents of HTML file is too long. When partial content of the file is downloaded due to slow network, browsers parse the partial content and wait the rest of content. In that moment, user event can be triggered. In line 21 of case6.html contains a long string and users can click button2 which calls a function button2Clicked in line 24 of case6.html. If line 24 of case6.html is not parsed yet and users click button2, a concurrency bug occurs.

Example

http://pswlab.kaist.ac.kr:81/case6.html

Reference

How browsers work, http://taligarsiel.com/Projects/howbrowserswork1.htm

Source code

case6.html

<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Case6</title>
</head>
<body>
<button onclick="button1Clicked()">Button1</button>
<script>
function button1Clicked() {
document.getElementById("outputButton1").innerHTML = "Button1 is clicked";
}
</script>
<div id="outputButton1"></div>
<div style="display: none;">
<!-- 1448011 characters -->
</div>
<button onclick="button2Clicked()">Button2</button>
<div id="outputButton2"></div>
<div style="display: none;">
<!-- 1448011 characters -->
</div>
<script>
function button2Clicked() {
document.getElementById("outputButton2").innerHTML = "Button2 is called";
}
</script>
</body>
</html>

Execution Model

Operations and an Inital Test Case

There are 5 operations in this example.

  • p1: parsing operation, parse line 1~15 of case6.html
  • p2: parsing operation, parse line 16~20 of case6.html
  • p3: parsing operation, parse line 21~29 of case6.html
  • u1: user event operation, trigger onclick event of button1
  • u2: user event operation, trigger onclick event of button2

The inital test case: p1 - p2 - p3 - u1 - u2

Happens-before Relations

  • For two parsing operations: (p1, p2), (p2, p3)
  • For two user event operations: (u1, u2)
  • For a parsing operation and a user event operation: (p1, u1), (p2, u2)

Generated Possible Test Cases

5 test cases are generated and 3 test cases of them are buggy because they contains (u2, p3).

Document Actions