@@ -50,31 +50,43 @@ var sendForAWhile = (function() {
50
50
var options ;
51
51
var tries ;
52
52
var parsedUrl ;
53
+ var success ;
53
54
54
- var tryInform = function ( ) {
55
- debug ( "inform: " + hftUrl ) ;
56
- io . sendJSON ( hftUrl , data , options , function ( err ) {
57
- // do I care?
58
- if ( err ) {
59
- ++ tries ;
60
- console . error ( "Try " + tries + " of " + config . getSettings ( ) . settings . rendezvousRetryTimes + ": Could not contact: " + parsedUrl . host ) ;
61
- console . error ( err ) ;
62
- if ( tries <= config . getSettings ( ) . settings . rendezvousRetryTimes ) {
63
- setTimeout ( tryInform , config . getSettings ( ) . settings . rendezvousRetryTimeout * 1000 ) ;
55
+ var tryInform = function ( tryOptions ) {
56
+ var tryUntilSuccess = function ( ) {
57
+ var localOptions = JSON . parse ( JSON . stringify ( options ) ) ;
58
+ localOptions . family = tryOptions . family ;
59
+ debug ( "inform: " + hftUrl + " family: " + localOptions . family ) ;
60
+ io . sendJSON ( hftUrl , data , localOptions , function ( err ) {
61
+ // do I care?
62
+ if ( err ) {
63
+ ++ tries [ localOptions . family ] ;
64
+ console . error ( "Try " + tries [ localOptions . family ] + " of " + config . getSettings ( ) . settings . rendezvousRetryTimes + ": Could not contact: " + parsedUrl . host + " family: " + localOptions . family ) ;
65
+ console . error ( err ) ;
66
+ if ( tries [ localOptions . family ] <= config . getSettings ( ) . settings . rendezvousRetryTimes ) {
67
+ // If one family succeeds then the other only needs 1 try.
68
+ if ( ! success ) {
69
+ setTimeout ( tryUntilSuccess , config . getSettings ( ) . settings . rendezvousRetryTimeout * 1000 ) ;
70
+ }
71
+ }
72
+ } else {
73
+ success = true ;
74
+ console . log ( "registered:" , data . addresses . join ( ", " ) , "with" , parsedUrl . hostname , "family:" , localOptions . family ) ;
64
75
}
65
- } else {
66
- console . log ( "registered:" , data . addresses . join ( ", " ) , "with" , parsedUrl . hostname ) ;
67
- }
68
- } ) ;
76
+ } ) ;
77
+ } ;
78
+ tryUntilSuccess ( ) ;
69
79
} ;
70
80
71
81
return function ( _url , _data , _options ) {
72
82
hftUrl = _url ;
73
83
parsedUrl = url . parse ( _url ) ;
74
84
data = _data ;
75
- options = _options ;
76
- tries = 0 ;
77
- tryInform ( ) ;
85
+ options = JSON . parse ( JSON . stringify ( _options ) ) ;
86
+ tries = { 4 : 0 , 6 : 0 } ;
87
+ success = false ;
88
+ tryInform ( { family :4 } ) ;
89
+ tryInform ( { family :6 } ) ;
78
90
} ;
79
91
} ( ) ) ;
80
92
@@ -96,7 +108,7 @@ var inform = (function() {
96
108
lastPort = g . port ;
97
109
var hftUrl = process . env . HFT_RENDEZVOUS_URL || config . getSettings ( ) . settings . rendezvousUrl ;
98
110
debug ( "ping: " + hftUrl ) ;
99
- var options = { headers : { } } ;
111
+ var options = { headers : { } , } ;
100
112
var rendezvousIp = process . env . HFT_RENDEZVOUS_IP ;
101
113
if ( rendezvousIp ) {
102
114
options . headers [ "x-forwarded-for" ] = rendezvousIp ;
0 commit comments