Skip to content

Python: Connection timeout is not respected in standalone mode when connection is refused #4991

@marcoffee

Description

@marcoffee

Describe the bug

When attempting to connect to a host where the Valkey server may be unavailable (e.g., the server is temporarily down or has crashed), the operation in standalone mode consistently blocks for about 5 to 6 seconds before raising an error. This happens even when a low connection timeout is configured. In contrast, when using cluster mode, connection failures are detected and errors are thrown almost immediately.

Expected Behavior

I expect that, when trying to connect to an unavailable host, the lib either:

  • fail when detecting that the host does not have a Valkey server running (similar to what happens in cluster mode)
  • respect the connection_timeout configuration and throw an exception as soon as it is reached.

Current Behavior

The GlideClient.create call blocks for about 5 to 6 seconds, regardless of connection_timeout.

Reproduction Steps

Below is a simple Python script to reproduce. Note that it should not have a server running at 127.0.0.2.

import asyncio
import glide

from datetime import datetime, UTC


async def test () -> None:
   print(datetime.now(UTC).isoformat(timespec="microseconds"))

   try:
      await glide.GlideClient.create(glide.GlideClientConfiguration(
         addresses=[glide.NodeAddress(host="127.0.0.2", port=6379)],
         database_id=0,
         request_timeout=1000,
         pubsub_subscriptions=None,
         protocol=glide.ProtocolVersion.RESP3,
         advanced_config=glide.AdvancedGlideClientConfiguration(
            connection_timeout=1000
         )
      ))

   finally:
      print(datetime.now(UTC).isoformat(timespec="microseconds"))

asyncio.run(test())

Possible Solution

Pass the connection timeout to socket connect call or implement the same give up behavior as in cluster mode.

Additional Information/Context

No response

Client version used

2.2.0

Engine type and version

Valkey 9.0

OS

Ubuntu 24.04

Language

Python

Language Version

3.13

Cluster information

No response

Logs

2025-11-19T18:18:08.456263Z  WARN logger_core: connection creation - Failed connecting to 127.0.0.2:6379, due to Connection refused (os error 111)
2025-11-19T18:18:08.456303Z ERROR logger_core: client creation - Connection error: Standalone(Received error for address `127.0.0.2:6379`: Connection refused (os error 111)
)
2025-11-19T18:18:08.456309Z ERROR logger_core: client creation - Connection error: Standalone(Received error for address `127.0.0.2:6379`: Connection refused (os error 111)
)
2025-11-19T18:18:08.456517Z  WARN logger_core: unhandled response error - Unhandled response error for unknown request: 4294967295

Other information

No response

Metadata

Metadata

Assignees

Labels

Optimization 🐌Optimization matter such as cleaner code, performance etcUser issue 🚨Issue opened by a userUsers PainAn issue known to cause users pain, generaly open by the user.bug 🐞Something isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions