@@ -6,6 +6,10 @@ import * as https from 'https';
66import type { AddressInfo } from 'net' ;
77import * as os from 'os' ;
88import * as path from 'path' ;
9+ import * as util from 'util' ;
10+
11+ const readFile = util . promisify ( fs . readFile ) ;
12+ const writeFile = util . promisify ( fs . writeFile ) ;
913
1014interface EventProxyServerOptions {
1115 /** Port to start the event proxy server at. */
@@ -123,9 +127,7 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
123127 const eventCallbackServerStartupPromise = new Promise < void > ( resolve => {
124128 const listener = eventCallbackServer . listen ( 0 , ( ) => {
125129 const port = String ( ( listener . address ( ) as AddressInfo ) . port ) ;
126- const tmpFileWithPort = path . join ( os . tmpdir ( ) , `event-proxy-server-${ options . proxyServerName } ` ) ;
127- fs . writeFileSync ( tmpFileWithPort , port , { encoding : 'utf8' } ) ;
128- resolve ( ) ;
130+ void registerCallbackServerPort ( options . proxyServerName , port ) . then ( resolve ) ;
129131 } ) ;
130132 } ) ;
131133
@@ -134,12 +136,11 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
134136 return ;
135137}
136138
137- export function waitForRequest (
139+ export async function waitForRequest (
138140 proxyServerName : string ,
139141 callback : ( eventData : SentryRequestCallbackData ) => boolean ,
140142) : Promise < SentryRequestCallbackData > {
141- const tmpFileWithPort = path . join ( os . tmpdir ( ) , `event-proxy-server-${ proxyServerName } ` ) ;
142- const eventCallbackServerPort = fs . readFileSync ( tmpFileWithPort , 'utf8' ) ;
143+ const eventCallbackServerPort = await retrieveCallbackServerPort ( proxyServerName ) ;
143144
144145 return new Promise < SentryRequestCallbackData > ( ( resolve , reject ) => {
145146 const request = http . request ( `http://localhost:${ eventCallbackServerPort } /` , { } , response => {
@@ -218,3 +219,15 @@ export function waitForTransaction(
218219 } ) . catch ( reject ) ;
219220 } ) ;
220221}
222+
223+ const TEMP_FILE_PREFIX = 'event-proxy-server-' ;
224+
225+ async function registerCallbackServerPort ( serverName : string , port : string ) : Promise < void > {
226+ const tmpFilePath = path . join ( os . tmpdir ( ) , `${ TEMP_FILE_PREFIX } ${ serverName } ` ) ;
227+ await writeFile ( tmpFilePath , port , { encoding : 'utf8' } ) ;
228+ }
229+
230+ async function retrieveCallbackServerPort ( serverName : string ) : Promise < string > {
231+ const tmpFilePath = path . join ( os . tmpdir ( ) , `${ TEMP_FILE_PREFIX } ${ serverName } ` ) ;
232+ return await readFile ( tmpFilePath , 'utf8' ) ;
233+ }
0 commit comments