WEB-25717 Docker debug does not work on Mac

This commit is contained in:
Vladimir Krivosheev
2017-03-13 14:18:28 +01:00
parent bb7868f450
commit 2837501cbd
2 changed files with 45 additions and 30 deletions
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -191,7 +191,7 @@ private fun connectNio(bootstrap: Bootstrap,
}
}
private fun sleep(promise: AsyncPromise<*>?, time: Int): Boolean {
fun sleep(promise: AsyncPromise<*>?, time: Int): Boolean {
try {
//noinspection BusyWait
Thread.sleep(time.toLong())
@@ -1,5 +1,5 @@
/*
* Copyright 2000-2016 JetBrains s.r.o.
* Copyright 2000-2017 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -22,10 +22,9 @@ import com.intellij.openapi.util.Condition
import com.intellij.ui.ColoredListCellRenderer
import com.intellij.ui.components.JBList
import com.intellij.util.io.connect
import com.intellij.util.io.sleep
import com.intellij.util.io.socketConnection.ConnectionStatus
import io.netty.bootstrap.Bootstrap
import io.netty.channel.ChannelFuture
import io.netty.util.concurrent.GenericFutureListener
import org.jetbrains.concurrency.*
import org.jetbrains.debugger.Vm
import org.jetbrains.io.NettyUtil
@@ -41,13 +40,9 @@ abstract class RemoteVmConnection : VmConnection<Vm>() {
var address: InetSocketAddress? = null
private val connectCancelHandler = AtomicReference<() -> Unit>()
protected val channelCloseListener = GenericFutureListener<ChannelFuture> {
close("Process disconnected unexpectedly", ConnectionStatus.DISCONNECTED)
}
abstract fun createBootstrap(address: InetSocketAddress, vmResult: AsyncPromise<Vm>): Bootstrap
@JvmOverloads
fun open(address: InetSocketAddress, stopCondition: Condition<Void>? = null): Promise<Vm> {
this.address = address
@@ -59,29 +54,49 @@ abstract class RemoteVmConnection : VmConnection<Vm>() {
if (Thread.interrupted()) {
return@executeOnPooledThread
}
var attemptNumber = 0
fun attempt() {
connectCancelHandler.set { result.setError("Closed explicitly") }
connectCancelHandler.set { result.setError("Closed explicitly") }
val connectionPromise = AsyncPromise<Any?>()
connectionPromise.rejected { result.setError(it) }
val connectionPromise = AsyncPromise<Any?>()
connectionPromise.rejected { result.setError(it) }
result
.done {
vm = it!!
setState(ConnectionStatus.CONNECTED, "Connected to ${connectedAddressToPresentation(address, it)}")
startProcessing()
}
.rejected {
if (it !is ConnectException) {
LOG.errorIfNotMessage(it)
result
.done {
vm = it!!
setState(ConnectionStatus.CONNECTED, "Connected to ${connectedAddressToPresentation(address, it)}")
startProcessing()
}
setState(ConnectionStatus.CONNECTION_FAILED, it.message)
}
.processed { connectCancelHandler.set(null) }
.rejected {
if (it !is ConnectException) {
LOG.errorIfNotMessage(it)
}
setState(ConnectionStatus.CONNECTION_FAILED, it.message)
}
.processed { connectCancelHandler.set(null) }
createBootstrap(address, result)
.connect(address, connectionPromise, maxAttemptCount = if (stopCondition == null) NettyUtil.DEFAULT_CONNECT_ATTEMPT_COUNT else -1, stopCondition = stopCondition)
?.let { it.closeFuture().addListener(channelCloseListener) }
createBootstrap(address, result)
.connect(address, connectionPromise,
maxAttemptCount = if (stopCondition == null) NettyUtil.DEFAULT_CONNECT_ATTEMPT_COUNT else -1,
stopCondition = stopCondition)
?.closeFuture()?.addListener {
if (result.isFulfilled) {
close("Process disconnected unexpectedly", ConnectionStatus.DISCONNECTED)
}
else {
if (++attemptNumber > 10 || (stopCondition?.value(null) ?: false)) {
result.setError("Process disconnected unexpectedly")
}
else {
sleep(result, 300)
attempt()
}
}
}
}
attempt()
}
connectCancelHandler.set {