File tree Expand file tree Collapse file tree 2 files changed +30
-3
lines changed
Expand file tree Collapse file tree 2 files changed +30
-3
lines changed Original file line number Diff line number Diff line change 6767 "permissions" : [
6868 " core.xhr" ,
6969 " core.oauth" ,
70- " core.storage"
70+ " core.storage" ,
71+ " core.tcpsocket"
7172 ]
7273}
Original file line number Diff line number Diff line change 11/// <reference path='../../../../third_party/typings/browser.d.ts' />
22
3+ import promises = require( '../../promises/promises' ) ;
4+
35declare const freedom : freedom . FreedomInModuleEnv ;
46
57// TODO: https://github.com/uProxy/uproxy/issues/2051
@@ -107,8 +109,32 @@ class Provisioner {
107109 break ;
108110 }
109111 }
110- console . log ( this . state_ ) ;
111- return this . state_ ;
112+
113+ // Spin until the server is truly up.
114+ // Give it one minute before declaring bankruptcy.
115+ console . log ( 'waiting for activity on port 22' ) ;
116+ return promises . retry ( ( ) => {
117+ const socket = freedom [ 'core.tcpsocket' ] ( ) ;
118+
119+ const destructor = ( ) => {
120+ try {
121+ freedom [ 'core.tcpsocket' ] . close ( socket ) ;
122+ } catch ( e ) {
123+ console . warn ( 'error destroying socket: ' + e . message ) ;
124+ }
125+ } ;
126+
127+ // TODO: Worth thinking about timeouts here but because this times
128+ // out almost immediately if nothing is listening on the port,
129+ // it works well for our purposes.
130+ return socket . connect ( this . state_ . network [ 'ipv4' ] , 22 ) . then ( ( unused : any ) => {
131+ destructor ( ) ;
132+ return this . state_ ;
133+ } , ( e : Error ) => {
134+ destructor ( ) ;
135+ throw e ;
136+ } ) ;
137+ } , 60 , 1000 ) ;
112138 } ) ;
113139 }
114140
You can’t perform that action at this time.
0 commit comments