Skip to content

Conversation

@Jiogo18
Copy link

@Jiogo18 Jiogo18 commented Nov 21, 2024

Tournament freeze on Timeout

If an agent timeout in a tournament, then its process is killed before the end of the match.
When Agent._terminate() is called, the process doesn't exist (this.process is never set to null).
So the promise is never solved and the tournament is stuck.

EPERM on Windows

If the two agents of a match never write to stderr, then Match.handleLogFiles() tries to remove the folder.
However, this will fail on Windows because errorLogWriteStream is never closed.
Since data can still be sent by the process after close, errorLogWriteStream status must be checked.

Patch for the npm packages

I don't expect this PR to be merged.
However, here is a patch for anyone in need.

$node_modules = "$env:AppData/npm/node_modules/@lux-ai/2021-challenge/node_modules"
# $node_modules = "node_modules"
$fileA = "$node_modules/dimensions-ai/lib/main/Agent/index.js"
$AgentContents = Get-Content $fileA
# Patch EPERM, line 800
$AgentContents = $AgentContents.replace('    Agent.prototype._terminate = function () {', '    Agent.prototype._terminate = function () { this.errorLogWriteStream?.close();')
# Patch tournament timeout, line 855
$AgentContents = $AgentContents.replace('if (exists) {', 'if (!exists) resolve(); else {')
Set-Content $fileA $AgentContents

$fileME = "$node_modules/dimensions-ai/lib/main/MatchEngine/index.js"
# Patch tournament ERR_STREAM_WRITE_AFTER_END, line 280
(Get-Content $fileME).replace('    errorLogWriteStream.write("" + data);', '    if (!errorLogWriteStream.writableEnded) errorLogWriteStream.write("" + data);') | Set-Content $fileME

If an agent timeout in a tournament, then its process is killed before the end of the match.
When `Agent._terminate()` is called, the process doesn't exist (`this.process` is never set to null).
So the promise is never solved and the tournament is stuck.

If the two agents of a match never write to stderr, then `Match.handleLogFiles()` tries to remove the folder.
However, this will fail on Windows because errorLogWriteStream is never closed.

Patch for the npm packages:
```ps1
$node_modules = "$env:AppData/npm/node_modules/@lux-ai/2021-challenge/node_modules"
# $node_modules = "node_modules"
$fileA = "$node_modules/dimensions-ai/lib/main/Agent/index.js"
$AgentContents = Get-Content $fileA
# Patch EPERM, line 800
$AgentContents = $AgentContents.replace('    Agent.prototype._terminate = function () {', '    Agent.prototype._terminate = function () { this.errorLogWriteStream?.close();')
# Patch tournament timeout, line 855
$AgentContents = $AgentContents.replace('if (exists) {', 'if (!exists) resolve(); else {')
Set-Content $fileA $AgentContents

$fileME = "$node_modules/dimensions-ai/lib/main/MatchEngine/index.js"
# Patch tournament ERR_STREAM_WRITE_AFTER_END, line 280
(Get-Content $fileME).replace('    errorLogWriteStream.write("" + data);', '    if (!errorLogWriteStream.writableEnded) errorLogWriteStream.write("" + data);') | Set-Content $fileME
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant