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


A long HTML content makes parsing stop at unsafe point


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.



How browsers work,

Source code


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

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