Skip to content

Commit 2d51dd8

Browse files
committed
Don't hold the lock while calling listenerStorage::Reset()
1 parent e4de8cc commit 2d51dd8

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

ntcore/src/main/native/cpp/InstanceImpl.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -230,10 +230,13 @@ void InstanceImpl::AddTimeSyncListener(NT_Listener listener,
230230
}
231231

232232
void InstanceImpl::Reset() {
233-
std::scoped_lock lock{m_mutex};
234-
// Listeners sometimes call NetworkTables APIs, so reset listenerStorage first
233+
// Listeners sometimes call NetworkTables APIs, so reset listenerStorage first.
234+
// Note: if there are queued events, this will wait until listeners are called,
235+
// and listeners may use this instance, so holding the lock could result in
236+
// deadlock.
235237
listenerStorage.Reset();
236238

239+
std::scoped_lock lock{m_mutex};
237240
m_networkServer.reset();
238241
m_networkClient.reset();
239242
m_servers.clear();

0 commit comments

Comments
 (0)