@@ -61,9 +61,9 @@ val myResourceLock = ReentrantLock()
61
61
class WslSymlinksProvider (distro : String ) {
62
62
val LOGGER = Logger .getInstance(WslSymlinksProvider ::class .java)
63
63
64
- private var process: Process
65
- private var processReader: BufferedReader
66
- private var processWriter: BufferedWriter
64
+ private var process: Process ? = null
65
+ private var processReader: BufferedReader ? = null
66
+ private var processWriter: BufferedWriter ? = null
67
67
private val queue: LinkedBlockingQueue <AsyncValue > = LinkedBlockingQueue ()
68
68
private val mapped: SynchronizedMap <String , AsyncValue > = SynchronizedMap ()
69
69
@@ -93,28 +93,28 @@ class WslSymlinksProvider(distro: String) {
93
93
val location = " \\\\ wsl.localhost\\ $distro \\ var\\ tmp\\ intellij-idea-wsl-symlinks.sh"
94
94
File (location).writeText(bash)
95
95
val builder = ProcessBuilder (" wsl.exe" , " -d" , distro, " -e" , " bash" , " //var/tmp/intellij-idea-wsl-symlinks.sh" )
96
- val process = builder.start()
97
- this .process = process
98
96
99
- val stdin: OutputStream = process.outputStream // <- Eh?
100
- val stdout: InputStream = process.inputStream
101
97
102
- val reader = BufferedReader (InputStreamReader (stdout))
103
- val writer = BufferedWriter (OutputStreamWriter (stdin))
104
- this .processReader = reader;
105
- this .processWriter = writer;
106
-
107
- process.onExit().whenComplete { t, u ->
108
- LOGGER .error(" process did exit" , u)
109
- this .process = builder.start()
98
+ fun setupProcess () {
99
+ val process = builder.start()
100
+ this .process = process
110
101
this .processReader = BufferedReader (InputStreamReader (process.inputStream))
111
102
this .processWriter = BufferedWriter (OutputStreamWriter (process.outputStream));
103
+ process.onExit().whenComplete { t, u ->
104
+ LOGGER .error(" process did exit ${u?.message ? : " no-reason" } " )
105
+ setupProcess()
106
+ }
112
107
}
113
108
109
+ setupProcess()
110
+
114
111
thread {
115
112
while (true ) {
116
113
try {
117
- val line = this .processReader.readLine()
114
+ if (this .processReader == null ) {
115
+ Thread .sleep(100 )
116
+ }
117
+ val line = this .processReader!! .readLine()
118
118
val (id, answer) = line.split(" ;" )
119
119
val a = mapped[id]!!
120
120
a.value = answer
@@ -131,11 +131,14 @@ class WslSymlinksProvider(distro: String) {
131
131
thread {
132
132
while (true ) {
133
133
try {
134
+ if (this .processWriter == null ) {
135
+ Thread .sleep(100 )
136
+ }
134
137
val a = this .queue.take()
135
138
if (a.value != null ) continue
136
139
mapped[a.id] = a
137
- this .processWriter.write(a.request!! )
138
- this .processWriter.flush()
140
+ this .processWriter!! .write(a.request!! )
141
+ this .processWriter!! .flush()
139
142
} catch (e: Exception ) {
140
143
LOGGER .error(" failed to write" , e)
141
144
}
0 commit comments