-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat-issue-215: increase randoness to decrease the rate of port colli… #219
Conversation
when I debug, I found error log:
so I check this log:
there was a panic info with so change this code:
static async nextPort(): Promise<number> {
this.lastPort = await portCheck.nextAvailable(this.lastPort + 1, '0.0.0.0');
return this.lastPort;
} so change this initial port to decrease potential port conflict: // 5001-60000, increase the range of initialPort to decrease the possibility of port conflict
function initialPort(): number {
-- return Math.max(1024, Math.floor(Math.random() * 10_000));
++ return Math.max(5001, Math.floor(Math.random() * 60_000));
}
static async nextPort(): Promise<number> {
this.lastPort = await portCheck.nextAvailable(this.lastPort + 1, '0.0.0.0');
return this.lastPort;
} if I change initialPort to a constant, It will occur above error with one hundred percent when I run two or more testfiles concurrently. function initialPort(): number {
return 5000;
} |
9541447
to
20dcf50
Compare
every async start(): Promise<SandboxServer> {
debug('Lifecycle.SandboxServer.start()');
const args = [
'--home',
this.homeDir,
'run',
'--rpc-addr',
`0.0.0.0:${this.port}`,
'--network-addr',
`0.0.0.0:${await SandboxServer.nextPort()}`,
];
if (process.env.NEAR_WORKSPACES_DEBUG) {
const filePath = join(this.homeDir, 'sandboxServer.log');
debug(`near-sandbox logs writing to file: ${filePath}`);
const fd = await open(filePath, 'a');
this.subprocess = spawn(SandboxServer.binPath, args, {
env: {RUST_BACKTRACE: 'full'},
// @ts-expect-error FileHandle not assignable to Stream | IOType
stdio: ['ignore', 'ignore', fd],
});
this.subprocess.on('exit', async () => {
await fd.close();
});
} else {
this.subprocess = spawn(SandboxServer.binPath, args, {
stdio: ['ignore', 'ignore', 'ignore'],
});
} |
Excellent analysis and fix! Thank you! Is it possible to completely prevent this error? By making a more robust version |
yep, we need to check whther this port is in used by other programs or other parallel testcases called |
#215