Skip to content

Commit 294f10b

Browse files
authored
PYTHON-4021 - Publish TopologyDescriptionChangedEvent on topology close (mongodb#1762)
1 parent 5699f80 commit 294f10b

14 files changed

+593
-119
lines changed

pymongo/asynchronous/topology.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,9 +664,31 @@ async def close(self) -> None:
664664
# Publish only after releasing the lock.
665665
if self._publish_tp:
666666
assert self._events is not None
667+
old_td = self._description
668+
self._description = TopologyDescription(
669+
TOPOLOGY_TYPE.Unknown,
670+
{},
671+
self._description.replica_set_name,
672+
self._description.max_set_version,
673+
self._description.max_election_id,
674+
self._description._topology_settings,
675+
)
676+
self._events.put(
677+
(
678+
self._listeners.publish_topology_description_changed,
679+
(
680+
old_td,
681+
self._description,
682+
self._topology_id,
683+
),
684+
)
685+
)
667686
self._events.put((self._listeners.publish_topology_closed, (self._topology_id,)))
668687
if self._publish_server or self._publish_tp:
688+
# Make sure the events executor thread is fully closed before publishing the remaining events
669689
self.__events_executor.close()
690+
self.__events_executor.join(1)
691+
process_events_queue(weakref.ref(self._events)) # type: ignore[arg-type]
670692

671693
@property
672694
def description(self) -> TopologyDescription:

pymongo/synchronous/topology.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,9 +662,31 @@ def close(self) -> None:
662662
# Publish only after releasing the lock.
663663
if self._publish_tp:
664664
assert self._events is not None
665+
old_td = self._description
666+
self._description = TopologyDescription(
667+
TOPOLOGY_TYPE.Unknown,
668+
{},
669+
self._description.replica_set_name,
670+
self._description.max_set_version,
671+
self._description.max_election_id,
672+
self._description._topology_settings,
673+
)
674+
self._events.put(
675+
(
676+
self._listeners.publish_topology_description_changed,
677+
(
678+
old_td,
679+
self._description,
680+
self._topology_id,
681+
),
682+
)
683+
)
665684
self._events.put((self._listeners.publish_topology_closed, (self._topology_id,)))
666685
if self._publish_server or self._publish_tp:
686+
# Make sure the events executor thread is fully closed before publishing the remaining events
667687
self.__events_executor.close()
688+
self.__events_executor.join(1)
689+
process_events_queue(weakref.ref(self._events)) # type: ignore[arg-type]
668690

669691
@property
670692
def description(self) -> TopologyDescription:

test/discovery_and_monitoring/rs/compatible.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"b:27017"
1717
],
1818
"minWireVersion": 0,
19-
"maxWireVersion": 6
19+
"maxWireVersion": 21
2020
}
2121
],
2222
[

test/discovery_and_monitoring/rs/compatible_unknown.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
"b:27017"
1717
],
1818
"minWireVersion": 0,
19-
"maxWireVersion": 6
19+
"maxWireVersion": 21
2020
}
2121
]
2222
],

test/discovery_and_monitoring/sharded/compatible.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
"isWritablePrimary": true,
2424
"msg": "isdbgrid",
2525
"minWireVersion": 0,
26-
"maxWireVersion": 6
26+
"maxWireVersion": 21
2727
}
2828
]
2929
],

test/discovery_and_monitoring/single/compatible.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"helloOk": true,
1212
"isWritablePrimary": true,
1313
"minWireVersion": 0,
14-
"maxWireVersion": 6
14+
"maxWireVersion": 21
1515
}
1616
]
1717
],

test/discovery_and_monitoring/single/too_old_then_upgraded.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"description": "Standalone with default maxWireVersion of 0 is upgraded to one with maxWireVersion 6",
2+
"description": "Standalone with default maxWireVersion of 0 is upgraded to one with maxWireVersion 21",
33
"uri": "mongodb://a",
44
"phases": [
55
{
@@ -35,7 +35,7 @@
3535
"helloOk": true,
3636
"isWritablePrimary": true,
3737
"minWireVersion": 0,
38-
"maxWireVersion": 6
38+
"maxWireVersion": 21
3939
}
4040
]
4141
],

0 commit comments

Comments
 (0)