Skip to content

Commit

Permalink
fix - Increase importer Max_Attempts & Refine getRandomPipePath (#1530)
Browse files Browse the repository at this point in the history
  • Loading branch information
Jiaaming authored Jul 26, 2024
1 parent ffc122d commit f7f93d4
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class NamedPipeStream {

private StreamProvider provider;

private final int MAX_ATTEMPTS = 5;
private final int MAX_ATTEMPTS = 30;

interface StreamProvider {
InputStream getInputStream() throws IOException;
Expand Down
4 changes: 2 additions & 2 deletions extension/src/bs/BuildServerConnector.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as net from "net";
import * as rpc from "vscode-jsonrpc/node";
import { generateRandomPipeName } from "../util/generateRandomPipeName";
import { getRandomPipeName } from "../util/generateRandomPipeName";

/**
* Creates a named pipe file and sets up a pipe server
Expand All @@ -16,7 +16,7 @@ export class BuildServerConnector {
* waiting for the connection from the Java build server.
*/
public setupBuildServerPipeStream(): void {
this.serverPipePath = generateRandomPipeName();
this.serverPipePath = getRandomPipeName();
this.serverPipeServer = net.createServer((socket: net.Socket) => {
this.serverConnection = rpc.createMessageConnection(
new rpc.StreamMessageReader(socket),
Expand Down
13 changes: 4 additions & 9 deletions extension/src/server/GradleServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Logger } from "../logger/index";
import { NO_JAVA_EXECUTABLE, OPT_RESTART } from "../constant";
import { redHatJavaInstalled } from "../util/config";
import { BspProxy } from "../bs/BspProxy";
import { generateRandomPipeName } from "../util/generateRandomPipeName";
import { getRandomPipeName } from "../util/generateRandomPipeName";
const SERVER_LOGLEVEL_REGEX = /^\[([A-Z]+)\](.*)$/;
const DOWNLOAD_PROGRESS_CHAR = ".";

Expand Down Expand Up @@ -39,14 +39,9 @@ export class GradleServer {
}

private setLanguageServerPipePath(): void {
try {
this.languageServerPipePath = generateRandomPipeName();
} catch (error) {
this.languageServerPipePath = "";
this.logger.error("Failed to generate language server pipe path", error.message);
sendInfo("", {
kind: "languageServerPipePathGenerationError",
});
this.languageServerPipePath = getRandomPipeName();
if (this.languageServerPipePath === "") {
this.logger.error("Failed to generate language server pipe path, language server will not start");
}
}

Expand Down
15 changes: 14 additions & 1 deletion extension/src/util/generateRandomPipeName.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// See: https://github.com/microsoft/vscode-languageserver-node/blob/6d0454dca7fba8529ba3fc6d930642f134291d3d/jsonrpc/src/node/main.ts#L176
import { randomBytes } from "crypto";
import { sendInfo } from "vscode-extension-telemetry-wrapper";
import * as os from "os";
import * as path from "path";
import * as fs from "fs";
Expand All @@ -11,7 +12,7 @@ const safeIpcPathLengths: Map<NodeJS.Platform, number> = new Map([
]);

// TODO: remove this function after upgrading vscode-languageclient
export function generateRandomPipeName(): string {
function generateRandomPipeName(): string {
if (process.platform === "win32") {
return `\\\\.\\pipe\\${randomBytes(16).toString("hex")}-sock`;
}
Expand All @@ -30,3 +31,15 @@ export function generateRandomPipeName(): string {
const randomSuffix = randomBytes(Math.floor(randomLength / 2)).toString("hex");
return path.join(tmpDir, `${randomSuffix}.sock`);
}

export function getRandomPipeName(): string {
let pipeName = "";
try {
pipeName = generateRandomPipeName();
} catch (error) {
sendInfo("", {
kind: "generateRandomPipeNameError",
});
}
return pipeName;
}

0 comments on commit f7f93d4

Please sign in to comment.