Skip to content

Missing error handling in PrivilegedClient #4

Description

@AndreySidorove

content: PrivilegedClient doesn't properly handle socket timeouts and connection errors
file: /server/PrivilegedClient.kt
code:

private suspend fun sendRaw(command: String): String? =
    withTimeoutOrNull(TIMEOUT_MS) {
        try {
            Socket("127.0.0.1", PrivilegedServer.PORT).use { socket ->
                socket.soTimeout = TIMEOUT_MS.toInt()
                PrintWriter(socket.outputStream, true).println(command)
                BufferedReader(InputStreamReader(socket.inputStream)).readLine()
            }
        } catch (_: Exception) {
            null
        }
    }

description: The catch block swallows all exceptions. Different error types should be handled differently (e.g., connection refused vs timeout).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions