Unverified Commit b88d3909 authored by fishyds's avatar fishyds Committed by GitHub
Browse files

Add ip address cached to resolve network issue (#220)

* Add ip address cached to resolve network issue
parent 9bb479bb
...@@ -245,18 +245,27 @@ function cleanupUnitTest(): void { ...@@ -245,18 +245,27 @@ function cleanupUnitTest(): void {
Container.restore(ExperimentStartupInfo); Container.restore(ExperimentStartupInfo);
} }
let cachedipv4Address : string = '';
/** /**
* Get IPv4 address of current machine * Get IPv4 address of current machine
*/ */
function getIPV4Address(): string { function getIPV4Address(): string {
let ipv4Address : string = ''; if (cachedipv4Address && cachedipv4Address.length > 0) {
return cachedipv4Address;
}
if(os.networkInterfaces().eth0) {
for(const item of os.networkInterfaces().eth0) { for(const item of os.networkInterfaces().eth0) {
if(item.family === 'IPv4') { if(item.family === 'IPv4') {
ipv4Address = item.address; cachedipv4Address = item.address;
return cachedipv4Address;
}
} }
} else {
throw Error('getIPV4Address() failed because os.networkInterfaces().eth0 is undefined.');
} }
return ipv4Address;
throw Error('getIPV4Address() failed because no valid IPv4 address found.')
} }
export { generateParamFileName, getMsgDispatcherCommand, getLogDir, getExperimentRootDir, export { generateParamFileName, getMsgDispatcherCommand, getLogDir, getExperimentRootDir,
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment