Skip to content

fix(redis): guard disconnect against null check operator exceptions on uninitialized socket close #657

Description

@ZhuchkaTriplesix

Motivation & Problem

In lib/core/database/redis_connection.dart (lines 135–145):

Future<void> disconnect() async {
  _isConnected = false;
  _command = null;
  final c = _conn;
  _conn = null;
  try {
    await c?.close();
  } catch (e) {
    debugPrint('RedisConnection.disconnect: ');
  }
}

Inside the redis package, calling close() on an uninitialized or already-closed connection performs an unguarded null assertion on the internal socket (_socket!.close()), throwing TypeError / Null check operator used on a null value and logging noisy errors.

Proposed Solution

  1. In RedisConnection.disconnect(), safely guard connection disposal and handle TypeError / Null check operator so that disconnects are idempotent and silent.
  2. Add unit tests verifying safe and idempotent disconnect calls.

Acceptance Criteria

  • Disconnecting an unconnected or failed Redis connection completes cleanly without throwing or logging null check exceptions.
  • Multiple consecutive disconnect() calls are idempotent.
  • Unit tests pass.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingerror-handlingTheme parser epic label: error-handlingstabilityTheme parser epic label: stability

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions