Abort thin client on access denied exception

There are situations in windows where it is possible that a client
attempts to connect to a portfile that it did not have access to. This
can happen if, for example, the server is started in administrator mode
but the client is started as a regular user. When this happens, the
client would try to remove the portfile and start a new server. This new
server would not actually be able to start a server though becuase it
would not be able to open the named point because the other server had
it open. As a result, the client would just hang. The fix is to just
abort the thin client if it gets an access denied exception.
This commit is contained in:
Ethan Atkins 2020-09-21 10:58:36 -07:00
parent 56cca22baf
commit 6247362725
1 changed files with 25 additions and 17 deletions

View File

@ -181,7 +181,12 @@ class NetworkClient(
catch {
// This catches a pipe busy exception which can happen if two windows clients
// 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 =>
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 {
@ -1093,7 +1098,7 @@ object NetworkClient {
System.exit(Terminal.withStreams(false) {
val term = Terminal.console
try client(base, restOfArgs, term.inputStream, System.err, term, useJNI)
finally {
catch { case _: AccessDeniedException => 1 } finally {
Runtime.getRuntime.removeShutdownHook(hook)
hook.run()
}
@ -1124,6 +1129,7 @@ object NetworkClient {
val sbtArgs = args.takeWhile(!_.startsWith(NetworkClient.completions))
val arguments = NetworkClient.parseArgs(sbtArgs)
val noTab = args.contains("--no-tab")
try {
val client =
simpleClient(
arguments.withBaseDirectory(baseDirectory),
@ -1139,6 +1145,7 @@ object NetworkClient {
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 =
@ -1153,4 +1160,5 @@ object NetworkClient {
e.printStackTrace()
1
}
private class AccessDeniedException extends Throwable
}