Skip to content

Commit b4f858f

Browse files
authored
Fix another instance of credentials being resolved on EDT (#2431)
1 parent 8483ddf commit b4f858f

File tree

2 files changed

+54
-38
lines changed

2 files changed

+54
-38
lines changed

jetbrains-core/src/software/aws/toolkits/jetbrains/services/lambda/python/PythonDebugUtils.kt

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,39 +9,47 @@ import com.intellij.xdebugger.XDebugProcessStarter
99
import com.intellij.xdebugger.XDebugSession
1010
import com.jetbrains.python.PythonHelper
1111
import com.jetbrains.python.debugger.PyDebugProcess
12+
import kotlinx.coroutines.Dispatchers
13+
import kotlinx.coroutines.withContext
1214
import software.aws.toolkits.jetbrains.services.PathMapper
1315
import software.aws.toolkits.jetbrains.services.PathMapping
1416
import software.aws.toolkits.jetbrains.services.lambda.execution.sam.SamRunningState
1517

1618
object PythonDebugUtils {
1719
const val DEBUGGER_VOLUME_PATH = "/tmp/lambci_debug_files"
1820

19-
fun createDebugProcess(
21+
suspend fun createDebugProcess(
2022
environment: ExecutionEnvironment,
2123
state: SamRunningState,
2224
debugHost: String,
2325
debugPorts: List<Int>
24-
): XDebugProcessStarter = object : XDebugProcessStarter() {
25-
override fun start(session: XDebugSession): XDebugProcess {
26+
): XDebugProcessStarter {
27+
val executionResult = withContext(Dispatchers.IO) {
28+
// needs to run off EDT since it resolves credentials
29+
state.execute(environment.executor, environment.runner)
30+
}
31+
32+
return object : XDebugProcessStarter() {
33+
override fun start(session: XDebugSession): XDebugProcess {
2634

27-
val mappings = state.pathMappings.plus(
28-
listOf(
29-
PathMapping(
30-
PythonHelper.DEBUGGER.pythonPathEntry,
31-
DEBUGGER_VOLUME_PATH
35+
val mappings = state.pathMappings.plus(
36+
listOf(
37+
PathMapping(
38+
PythonHelper.DEBUGGER.pythonPathEntry,
39+
DEBUGGER_VOLUME_PATH
40+
)
3241
)
3342
)
34-
)
3543

36-
val executionResult = state.execute(environment.executor, environment.runner)
37-
return PyDebugProcess(
38-
session,
39-
executionResult.executionConsole,
40-
executionResult.processHandler,
41-
debugHost,
42-
debugPorts.first()
43-
).also {
44-
it.positionConverter = PathMapper.PositionConverter(PathMapper(mappings))
44+
return PyDebugProcess(
45+
session,
46+
executionResult.executionConsole,
47+
executionResult.processHandler,
48+
debugHost,
49+
debugPorts.first()
50+
).also {
51+
it.positionConverter = PathMapper.PositionConverter(PathMapper(mappings))
52+
}
4553
}
4654
}
4755
}

jetbrains-ultimate/src/software/aws/toolkits/jetbrains/services/lambda/nodejs/NodeJsDebugUtils.kt

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ import com.intellij.xdebugger.XDebugProcessStarter
1717
import com.intellij.xdebugger.XDebugSession
1818
import com.jetbrains.debugger.wip.WipLocalVmConnection
1919
import com.jetbrains.nodeJs.NodeChromeDebugProcess
20+
import kotlinx.coroutines.Dispatchers
21+
import kotlinx.coroutines.withContext
2022
import org.jetbrains.io.LocalFileFinder
2123
import software.aws.toolkits.jetbrains.services.PathMapping
2224
import software.aws.toolkits.jetbrains.services.lambda.execution.sam.SamRunningState
@@ -25,36 +27,42 @@ import java.net.InetSocketAddress
2527
object NodeJsDebugUtils {
2628
private const val NODE_MODULES = "node_modules"
2729

28-
fun createDebugProcess(
30+
suspend fun createDebugProcess(
2931
environment: ExecutionEnvironment,
3032
state: SamRunningState,
3133
debugHost: String,
3234
debugPorts: List<Int>
33-
): XDebugProcessStarter = object : XDebugProcessStarter() {
34-
override fun start(session: XDebugSession): XDebugProcess {
35-
val mappings = createBiMapMappings(state.pathMappings)
36-
val fileFinder = RemoteDebuggingFileFinder(mappings, LocalFileSystemFileFinder())
35+
): XDebugProcessStarter {
36+
val executionResult = withContext(Dispatchers.IO) {
37+
// needs to run off EDT since it resolves credentials
38+
state.execute(environment.executor, environment.runner)
39+
}
40+
41+
return object : XDebugProcessStarter() {
42+
override fun start(session: XDebugSession): XDebugProcess {
43+
val mappings = createBiMapMappings(state.pathMappings)
44+
val fileFinder = RemoteDebuggingFileFinder(mappings, LocalFileSystemFileFinder())
3745

38-
val connection = WipLocalVmConnection()
39-
val executionResult = state.execute(environment.executor, environment.runner)
46+
val connection = WipLocalVmConnection()
4047

41-
val process = NodeChromeDebugProcess(session, fileFinder, connection, executionResult)
48+
val process = NodeChromeDebugProcess(session, fileFinder, connection, executionResult)
4249

43-
val processHandler = executionResult.processHandler
44-
val socketAddress = InetSocketAddress(debugHost, debugPorts.first())
50+
val processHandler = executionResult.processHandler
51+
val socketAddress = InetSocketAddress(debugHost, debugPorts.first())
4552

46-
if (processHandler == null || processHandler.isStartNotified) {
47-
connection.open(socketAddress)
48-
} else {
49-
processHandler.addProcessListener(
50-
object : ProcessAdapter() {
51-
override fun startNotified(event: ProcessEvent) {
52-
connection.open(socketAddress)
53+
if (processHandler == null || processHandler.isStartNotified) {
54+
connection.open(socketAddress)
55+
} else {
56+
processHandler.addProcessListener(
57+
object : ProcessAdapter() {
58+
override fun startNotified(event: ProcessEvent) {
59+
connection.open(socketAddress)
60+
}
5361
}
54-
}
55-
)
62+
)
63+
}
64+
return process
5665
}
57-
return process
5866
}
5967
}
6068

0 commit comments

Comments
 (0)