Skip to content

BrokenRedisTests.TestWeAbortConnection fails: ObjectDisposedException instead of RedisConnectionException #12

@gfraiteur

Description

@gfraiteur

Summary

BrokenRedisTests.TestWeAbortConnection test fails on the .NET Framework test configuration. The test expects a RedisConnectionException when connecting to a non-existent Redis endpoint, but instead receives an ObjectDisposedException.

Build

Error

Assert.Throws() Failure: Exception type was not an exact match
Expected: typeof(StackExchange.Redis.RedisConnectionException)
Actual:   typeof(System.ObjectDisposedException)
---- System.ObjectDisposedException : Cannot access a disposed object.
Object name: 'Connection is being disposed'.

Stack trace: The ObjectDisposedException originates from RedisCachingBackend.InitAsync at Database.PingAsync() (RedisCachingBackend.cs:122), called from RedisCachingBackend.CreateAsync (RedisCachingBackend.cs:283).

Analysis

The test (Tests/Patterns/PostSharp.Patterns.Caching.Tests/Backends/Redis/BrokenRedisTests.cs) connects to 192.168.45.127:12345 (a non-existent endpoint) with AbortOnConnectFail = false and a very short timeout (10ms). It expects RedisCachingBackend.CreateAsync to throw RedisConnectionException.

However, with the current version of StackExchange.Redis and/or .NET SDK 10.0, the connection object is disposed before PingAsync is called, resulting in ObjectDisposedException instead of RedisConnectionException.

This is likely caused by a behavioral change in a newer version of StackExchange.Redis where the connection multiplexer disposal races with the ping attempt on a failed connection.

Possible Fix

Either:

  1. Update the test to also accept ObjectDisposedException (if both exception types are valid)
  2. Catch ObjectDisposedException in RedisCachingBackend.InitAsync/CreateAsync and wrap it in a more meaningful exception

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions