Skip to content

Impossible to connect to a single member replica set through PHP library #1557

Open
@alterphp

Description

@alterphp

Bug Report

I'm using a single member replica set MongoDB cluster in my development environment (and also in production in some cases), but replica set is well configured. With mongosh, I can connect to the single member by spefying the replicaSet URI parameter and it works well.

Using PHP driver, if I set a replicaSet option, I get an error No suitable servers found (serverSelectionTryOnce set): [connection refused calling hello on '127.0.0.1:27017']. Topology type: ReplicaSetNoPrimary. But through mongosh, I can check that my single member is obviously seen as PRIMARY :

{
  set: 'rs_dev',
  date: ISODate('2024-12-17T17:09:57.780Z'),
  myState: 1,
  term: Long('16'),
  syncSourceHost: '',
  syncSourceId: -1,
  heartbeatIntervalMillis: Long('2000'),
  majorityVoteCount: 1,
  writeMajorityCount: 1,
  votingMembersCount: 1,
  writableVotingMembersCount: 1,
  optimes: { ... },
  lastStableRecoveryTimestamp: Timestamp({ t: 1734455354, i: 1 }),
  electionCandidateMetrics: { ... },
  members: [
    {
      _id: 0,
      name: '127.0.0.1:27017',
      health: 1,
      state: 1,
      stateStr: 'PRIMARY',
      uptime: 3284,
      optime: { ts: Timestamp({ t: 1734455394, i: 1 }), t: Long('16') },
      optimeDate: ISODate('2024-12-17T17:09:54.000Z'),
      lastAppliedWallTime: ISODate('2024-12-17T17:09:54.533Z'),
      lastDurableWallTime: ISODate('2024-12-17T17:09:54.533Z'),
      syncSourceHost: '',
      syncSourceId: -1,
      infoMessage: '',
      electionTime: Timestamp({ t: 1734452114, i: 1 }),
      electionDate: ISODate('2024-12-17T16:15:14.000Z'),
      configVersion: 1,
      configTerm: 16,
      self: true,
      lastHeartbeatMessage: ''
    }
  ],
  ok: 1,
  '$clusterTime': {...},
  operationTime: Timestamp({ t: 1734455394, i: 1 })
}

Environment

I'm not using TLS in dev environment, MongoDB is a Docker container (version 7.0) configured with configured rs_dev ReplicaSet.

Library mongodb/mongodb is 1.19.1
PHP is 8.1
PHP extension is 1.20.1

It seems to be handled the same way by NodeJS driver (same issue described here : https://stackoverflow.com/questions/69531947/replicasetnoprimary-error-although-primary-exists).

Please tell me if this is expected behavior, although mongosh seems OK with single member replica set ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions