Skip to content
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

Fix spawning of terminfo thread in server mode #3833

Merged
merged 5 commits into from
Oct 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions main/client/src/mill/main/client/ServerLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ public static class Result{
final int serverProcessesLimit = 5;
final int serverInitWaitMillis = 10000;
public abstract void initServer(Path serverDir, boolean b, Locks locks) throws Exception;
public abstract void preRun(Path serverDir) throws Exception;
InputStream stdin;
PrintStream stdout;
PrintStream stderr;
Expand Down Expand Up @@ -101,6 +102,7 @@ public Result acquireLocksAndRun(String outDir) throws Exception {
) {
if (clientLocked.isLocked()) {
Result result = new Result();
preRun(serverDir);
result.exitCode = run(serverDir, setJnaNoSys, locks);
result.serverDir = serverDir;
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ object ClientServerTests extends TestSuite {
memoryLocks,
forceFailureForTestingMillisDelay
) {
def preRun(serverDir: Path) = { /*do nothing*/ }
def initServer(serverDir: Path, b: Boolean, locks: Locks) = {
val serverId = "server-" + nextServerId
nextServerId += 1
Expand Down
3 changes: 3 additions & 0 deletions runner/client/src/mill/runner/client/MillClientMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,9 @@ public static void main(String[] args) throws Exception {
public void initServer(Path serverDir, boolean setJnaNoSys, Locks locks) throws Exception{
MillProcessLauncher.launchMillServer(serverDir, setJnaNoSys);
}
public void preRun(Path serverDir) throws Exception {
MillProcessLauncher.runTermInfoThread(serverDir);
}
};
int exitCode = launcher.acquireLocksAndRun(OutFiles.out).exitCode;
if (exitCode == Util.ExitServerCodeWhenVersionMismatch()) {
Expand Down
48 changes: 25 additions & 23 deletions runner/client/src/mill/runner/client/MillProcessLauncher.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import java.nio.file.Paths;
import java.util.*;

import mill.main.client.DebugLog;
import org.jline.terminal.TerminalBuilder;
import org.jline.terminal.Terminal;

Expand Down Expand Up @@ -37,7 +38,9 @@ static int launchMillNoServer(String[] args) throws Exception {
boolean interrupted = false;

try {
return configureRunMillProcess(builder, processDir).waitFor();
Process p = configureRunMillProcess(builder, processDir);
MillProcessLauncher.runTermInfoThread(processDir);
return p.waitFor();

} catch (InterruptedException e) {
interrupted = true;
Expand Down Expand Up @@ -71,30 +74,9 @@ static Process configureRunMillProcess(
ProcessBuilder builder,
Path serverDir
) throws Exception {
Terminal term = TerminalBuilder.builder().dumb(true).build();

Path sandbox = serverDir.resolve(ServerFiles.sandbox);
Files.createDirectories(sandbox);
Files.write(
serverDir.resolve(ServerFiles.terminfo),
(term.getWidth() + " " + term.getHeight()).getBytes()
);
Thread termInfoPropagatorThread = new Thread(
() -> {
try {

while(true){
Files.write(
serverDir.resolve(ServerFiles.terminfo),
(term.getWidth() + " " + term.getHeight()).getBytes()
);

Thread.sleep(100);
}
}catch (Exception e){}
},
"TermInfoPropagatorThread"
);
termInfoPropagatorThread.start();
builder.environment().put(EnvVars.MILL_WORKSPACE_ROOT, new File("").getCanonicalPath());

builder.directory(sandbox.toFile());
Expand Down Expand Up @@ -214,4 +196,24 @@ static List<String> millLaunchJvmCommand(boolean setJnaNoSys) throws Exception {
static List<String> readMillJvmOpts() {
return Util.readOptsFileLines(millJvmOptsFile());
}

public static void runTermInfoThread(Path serverDir) throws Exception{
Terminal term = TerminalBuilder.builder().dumb(true).build();
Thread termInfoPropagatorThread = new Thread(
() -> {
try {
while(true){
Files.write(
serverDir.resolve(ServerFiles.terminfo),
(term.getWidth() + " " + term.getHeight()).getBytes()
);

Thread.sleep(100);
}
}catch (Exception e){}
},
"TermInfoPropagatorThread"
);
termInfoPropagatorThread.start();
}
}
Loading