Skip to content

Commit

Permalink
Sleep while polling sockets on Windows (#5594)
Browse files Browse the repository at this point in the history
  • Loading branch information
nirinchev authored Jun 17, 2022
1 parent af2a8b7 commit def0126
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
* Fix a data race when opening a flexible sync Realm (since v12.1.0).
* Fixed a missing backlink removal when setting a Mixed from a TypedLink to null or any other non-link value. Users may have seen exception of "key not found" or assertion failures such as `mixed.hpp:165: [realm-core-12.1.0] Assertion failed: m_type` when removing the destination link object. ([#5574](https://github.com/realm/realm-core/pull/5573), since the introduction of Mixed in v11.0.0)
* Asymmetric sync now works with embedded objects. (Issue [#5565](https://github.com/realm/realm-core/issues/5565), since 12.1.0)

* Fixed an issue on Windows that would cause high CPU usage by the sync client when there are no active sync sessions. (Issue [#5591](https://github.com/realm/realm-core/issues/5591), since the introduction of Sync support for Windows)

### Breaking changes
* `realm_sync_before_client_reset_func_t` and `realm_sync_after_client_reset_func_t` in the C API now return a boolean value to indicate whether the callback succeeded or not, which signals to the sync client that a fatal error occurred. (PR [#5564](https://github.com/realm/realm-core/pull/5564))

Expand Down
13 changes: 10 additions & 3 deletions src/realm/util/network.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1142,7 +1142,7 @@ bool Service::IoReactor::wait_and_advance(clock::time_point timeout, clock::time
auto started = steady_clock::now();
int ret = 0;

do {
for (;;) {
if (m_pollfd_slots.size() > 1) {
// Poll all network sockets
ret = WSAPoll(LPWSAPOLLFD(&m_pollfd_slots[1]), ULONG(m_pollfd_slots.size() - 1),
Expand All @@ -1155,8 +1155,15 @@ bool Service::IoReactor::wait_and_advance(clock::time_point timeout, clock::time
ret++;
}

} while (ret == 0 &&
(duration_cast<milliseconds>(steady_clock::now() - started).count() < max_wait_millis));
if (ret != 0 ||
(duration_cast<milliseconds>(steady_clock::now() - started).count() >= max_wait_millis)) {
break;
}

// If we don't have any sockets to poll for (m_pollfd_slots is less than 2) and no one signals
// the wakeup pipe, we'd be stuck busy waiting for either condition to become true.
std::this_thread::sleep_for(std::chrono::milliseconds(socket_poll_timeout));
}

#else // !defined _WIN32
int ret = ::poll(fds, nfds, max_wait_millis);
Expand Down

0 comments on commit def0126

Please sign in to comment.