Skip to content

Commit 203a83f

Browse files
committed
prevent double firing of cb on contract.new race condition
1 parent a3eb6c0 commit 203a83f

File tree

6 files changed

+35
-16
lines changed

6 files changed

+35
-16
lines changed

dist/web3-light.js

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web3-light.min.js

+3-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web3.js

+9-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web3.js.map

+2-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/web3.min.js

+3-3
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/web3/contract.js

+9-3
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,12 @@ var contract = function (abi) {
105105
* @returns {Undefined}
106106
*/
107107
var checkForContractAddress = function(contract, abi, callback){
108-
var count = 0;
108+
var count = 0,
109+
callbackFired = false;
109110

110111
// wait for receipt
111112
var filter = web3.eth.filter('latest', function(e){
112-
if(!e) {
113+
if(!e && !callbackFired) {
113114
count++;
114115

115116
// console.log('Checking for contract address', count);
@@ -118,6 +119,7 @@ var checkForContractAddress = function(contract, abi, callback){
118119
if(count > 50) {
119120

120121
filter.stopWatching();
122+
callbackFired = true;
121123

122124
if(callback)
123125
callback(new Error('Contract transaction couldn\'t be found after 50 blocks'));
@@ -128,11 +130,15 @@ var checkForContractAddress = function(contract, abi, callback){
128130
} else {
129131

130132
web3.eth.getTransactionReceipt(contract.transactionHash, function(e, receipt){
131-
if(receipt) {
133+
if(receipt && !callbackFired) {
132134

133135
web3.eth.getCode(receipt.contractAddress, function(e, code){
136+
137+
if(callbackFired)
138+
return;
134139

135140
filter.stopWatching();
141+
callbackFired = true;
136142

137143
if(code.length > 2) {
138144

0 commit comments

Comments
 (0)