A golang-driven exception error

We maintain a replica set in PSA mode in k8s. For some reasons, we redeployed the cluster, and then our application (using golang driver) could not write to the database, reporting an error:

topology.ServerSelectionError=server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: xxxxxxl:27017, Type: Unknown, Last error: was a primary, but its set version or election id is stale }, { Addr: xxxxxxl:27017, Type: RSSecondary, Average RTT: 1091734 }, { Addr: xxxxxxl:27017, Type: RSArbiter, Average RTT: 1005485 }, ] }

but directly connected to the cluster through the mongo shell The write operation can be performed at that time, and the status of the cluster is also displayed as normal. After we restart the application, the fault is restored. But we don’t know the cause of the failure, why the application doesn’t continue to work after the DB cluster is restarted

mongod version: 4.4.10
golang-driver: 1.8.4

I am seeing this same problem with Golang driver 1.12.1
The replica set has a primary, but the go client thinks that the primary is stale.
Recycling the client works around the issue :confused:

At least in my case I believe that the issue was that the mongodb was completely recycled during testing, setting some set version number and election id backwards but the driver expects them to be monotonically increasing, thus the “stale” message