@@ -6,6 +6,10 @@ import * as https from 'https';
6
6
import type { AddressInfo } from 'net' ;
7
7
import * as os from 'os' ;
8
8
import * 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 ) ;
9
13
10
14
interface EventProxyServerOptions {
11
15
/** Port to start the event proxy server at. */
@@ -123,9 +127,7 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
123
127
const eventCallbackServerStartupPromise = new Promise < void > ( resolve => {
124
128
const listener = eventCallbackServer . listen ( 0 , ( ) => {
125
129
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 ) ;
129
131
} ) ;
130
132
} ) ;
131
133
@@ -134,12 +136,11 @@ export async function startEventProxyServer(options: EventProxyServerOptions): P
134
136
return ;
135
137
}
136
138
137
- export function waitForRequest (
139
+ export async function waitForRequest (
138
140
proxyServerName : string ,
139
141
callback : ( eventData : SentryRequestCallbackData ) => boolean ,
140
142
) : 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 ) ;
143
144
144
145
return new Promise < SentryRequestCallbackData > ( ( resolve , reject ) => {
145
146
const request = http . request ( `http://localhost:${ eventCallbackServerPort } /` , { } , response => {
@@ -218,3 +219,15 @@ export function waitForTransaction(
218
219
} ) . catch ( reject ) ;
219
220
} ) ;
220
221
}
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