Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion apps/frontend/src/components/ValkeyReconnect.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { useDispatch, useSelector } from "react-redux"
import { useNavigate, useParams } from "react-router"
import { CONNECTED, CONNECTING, ERROR } from "@common/src/constants"
import { Loader2, Database, AlertCircle } from "lucide-react"
import * as R from "ramda"
import RetryProgress from "./ui/retry-progress"
import { PasswordPromptModal } from "./ui/password-prompt-modal"
import type { RootState } from "@/store"
Expand All @@ -20,7 +21,7 @@ export function ValkeyReconnect() {

const { status, errorMessage, reconnect } = connection || {}
const [showPasswordPrompt, setShowPasswordPrompt] = useState(false)
const needsPassword = connection?.connectionDetails.password === undefined
const needsPassword = R.isNil(connection?.connectionDetails.password)

// Close password prompt on successful connection
useEffect(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@ export const ClusterConnectionGroup = ({ clusterId, connections, highlight = "",

const handleConnectLatest = () => {
if (!lastOpenedNode) return
if (lastOpenedNode.connection.connectionDetails.password === undefined && onPasswordRequired) {
const { password, authType } = lastOpenedNode.connection.connectionDetails
if (authType !== "iam" && R.isNil(password) && onPasswordRequired) {
onPasswordRequired(lastOpenedNode.connectionId)
return
}
Expand Down
4 changes: 3 additions & 1 deletion apps/frontend/src/components/connection/ConnectionEntry.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { CONNECTED, ERROR, CONNECTING } from "@common/src/constants.ts"
import * as R from "ramda"
import { CircleChevronRight, Server } from "lucide-react"
import { Link } from "react-router"
import {
Expand Down Expand Up @@ -41,7 +42,8 @@ export const ConnectionEntry = ({

const handleDisconnect = () => dispatch(closeConnection({ connectionId }))
const handleConnect = () => {
if (connection.connectionDetails.password === undefined && onPasswordRequired) {
const { password, authType } = connection.connectionDetails
if (authType !== "iam" && R.isNil(password) && onPasswordRequired) {
onPasswordRequired(connectionId)
return
}
Expand Down
4 changes: 2 additions & 2 deletions apps/frontend/src/state/epics/valkeyEpics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ export const valkeyRetryEpic = (store: Store) =>
return EMPTY
}

if (connection.connectionDetails.password === undefined) {
if (R.isNil(connection.connectionDetails.password)) {
console.debug(`Password unavailable for ${connectionId}, skipping auto-retry`)
store.dispatch(stopRetry({ connectionId }))
return EMPTY
Expand Down Expand Up @@ -223,7 +223,7 @@ export const autoReconnectEpic = (store: Store) =>

const disconnectedConnections = Object.entries(connections)
.filter(([, connection]) => connection.status === DISCONNECTED)
.filter(([, connection]) => connection.connectionDetails.password !== undefined && connection.connectionDetails.password !== "")
.filter(([, connection]) => R.isNotNil(connection.connectionDetails.password))

if (disconnectedConnections.length > 0) {
console.log(`Auto-reconnecting ${disconnectedConnections.length} connection(s)`)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,10 @@ const connectionSlice = createSlice({
errorMessage: isRetry && existingConnection?.errorMessage ? existingConnection.errorMessage : null,
connectionDetails: {
...connectionDetails,
// Strip password from state if secure storage is unavailable to prevent unencrypted persistence.
password: connectionDetails.password && secureStorage.isAvailable() ? connectionDetails.password : undefined,
// Preserve "" (no-password connections) but strip real passwords if secure storage is unavailable
password: (R.isNotNil(connectionDetails.password) && secureStorage.isAvailable()) || R.isEmpty(connectionDetails.password)
? connectionDetails.password
: undefined,
clusterSlotStatsEnabled: false,
jsonModuleAvailable: false,
},
Expand Down
9 changes: 5 additions & 4 deletions apps/metrics/src/valkey-client.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,14 @@ export const createValkeyClient = async (cfg = {}) => {
addresses,
credentials,
useTLS,
...(useTLS && process.env.VALKEY_VERIFY_CERT === "false" && {
advancedConfiguration: {
advancedConfiguration: {
...(useTLS && process.env.VALKEY_VERIFY_CERT === "false" && {
tlsAdvancedConfiguration: {
insecure: true,
},
},
}),
}),
connectionTimeout: 30000,
},
requestTimeout: 5000,
}

Expand Down
1 change: 1 addition & 0 deletions apps/metrics/src/valkey-client.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ describe("valkey client mode selection", () => {
tlsAdvancedConfiguration: {
insecure: true,
},
connectionTimeout: 30000,
},
requestTimeout: 5000,
clientName: "valkey_admin_metrics_cluster_client",
Expand Down
1 change: 1 addition & 0 deletions apps/server/src/__tests__/connection.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,7 @@ describe("connectToValkey", () => {
tls: false,
verifyTlsCertificate: false,
connectionId: "conn-456",
endpointType: "node",
} as ConnectionDetails,
connectionId: "",
}
Expand Down
8 changes: 1 addition & 7 deletions apps/server/src/connection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -226,13 +226,7 @@ export async function connectToCluster(
const { connectionId } = payload
const { verifyTlsCertificate, tls: useTLS } = payload.connectionDetails
try {
const CONNECTION_TIMEOUT_MS = 10000
let clusterClient = await Promise.race([
createClusterValkeyClient({ addresses, credentials, useTLS, verifyTlsCertificate }),
new Promise<never>((_, reject) =>
setTimeout(() => reject(new Error("Connection timed out")), CONNECTION_TIMEOUT_MS),
),
])
let clusterClient = await createClusterValkeyClient({ addresses, credentials, useTLS, verifyTlsCertificate })

// TODO: Optimize to not call discoverCluster when configEndpointId is available
// It implies we already discovered cluster nodes once
Expand Down
9 changes: 5 additions & 4 deletions apps/server/src/valkey-client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,14 @@ const buildSharedOptions = ({
addresses,
credentials,
useTLS,
...(useTLS && verifyTlsCertificate === false && {
advancedConfiguration: {
advancedConfiguration: {
...(useTLS && verifyTlsCertificate === false && {
tlsAdvancedConfiguration: {
insecure: true,
},
},
}),
}),
connectionTimeout: 30000,
},
requestTimeout: 5000,
})

Expand Down
Loading