Merge pull request #5879 from eatkins/windows-access-denied

Abort thin client on access denied exception
This commit is contained in:
eugene yokota 2020-09-21 14:29:07 -04:00 committed by GitHub
commit 6e181ac843
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 25 additions and 17 deletions

View File

@ -181,8 +181,13 @@ class NetworkClient(
catch { catch {
// This catches a pipe busy exception which can happen if two windows clients // This catches a pipe busy exception which can happen if two windows clients
// attempt to connect in rapid succession // attempt to connect in rapid succession
case e: IOException if e.getMessage.contains("Couldn't open") && attempt < 10 => None case e: IOException if e.getMessage.contains("Couldn't open") && attempt < 10 =>
case e: IOException => throw new ConnectionRefusedException(e) if (e.getMessage.contains("Access is denied") || e.getMessage.contains("(5)")) {
errorStream.println(s"Access denied for portfile $portfile")
throw new NetworkClient.AccessDeniedException
}
None
case e: IOException => throw new ConnectionRefusedException(e)
} }
res match { res match {
case Some(r) => r case Some(r) => r
@ -1093,7 +1098,7 @@ object NetworkClient {
System.exit(Terminal.withStreams(false) { System.exit(Terminal.withStreams(false) {
val term = Terminal.console val term = Terminal.console
try client(base, restOfArgs, term.inputStream, System.err, term, useJNI) try client(base, restOfArgs, term.inputStream, System.err, term, useJNI)
finally { catch { case _: AccessDeniedException => 1 } finally {
Runtime.getRuntime.removeShutdownHook(hook) Runtime.getRuntime.removeShutdownHook(hook)
hook.run() hook.run()
} }
@ -1124,21 +1129,23 @@ object NetworkClient {
val sbtArgs = args.takeWhile(!_.startsWith(NetworkClient.completions)) val sbtArgs = args.takeWhile(!_.startsWith(NetworkClient.completions))
val arguments = NetworkClient.parseArgs(sbtArgs) val arguments = NetworkClient.parseArgs(sbtArgs)
val noTab = args.contains("--no-tab") val noTab = args.contains("--no-tab")
val client =
simpleClient(
arguments.withBaseDirectory(baseDirectory),
inputStream = in,
errorStream = errorStream,
printStream = errorStream,
useJNI = useJNI,
)
try { try {
val results = val client =
if (client.connect(log = false, promptCompleteUsers = true)) client.getCompletions(cmd) simpleClient(
else Nil arguments.withBaseDirectory(baseDirectory),
out.println(results.sorted.distinct mkString "\n") inputStream = in,
0 errorStream = errorStream,
} catch { case _: Exception => 1 } finally client.close() printStream = errorStream,
useJNI = useJNI,
)
try {
val results =
if (client.connect(log = false, promptCompleteUsers = true)) client.getCompletions(cmd)
else Nil
out.println(results.sorted.distinct mkString "\n")
0
} catch { case _: Exception => 1 } finally client.close()
} catch { case _: AccessDeniedException => 1 }
} }
def run(configuration: xsbti.AppConfiguration, arguments: List[String]): Int = def run(configuration: xsbti.AppConfiguration, arguments: List[String]): Int =
@ -1153,4 +1160,5 @@ object NetworkClient {
e.printStackTrace() e.printStackTrace()
1 1
} }
private class AccessDeniedException extends Throwable
} }