Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix network recovery #64

Merged
merged 1 commit into from
Sep 29, 2020
Merged

Fix network recovery #64

merged 1 commit into from
Sep 29, 2020

Conversation

scottinet
Copy link
Contributor

Description

Fix a number of problems when handling disconnections, and with asynchronous tasks in general.

Network disconnection

When AbstractProtocol.AutoRecover is set to true:

  • requests sent through the network would never be resolved when the connection is lost before they receive a response. This means that clients awaiting for a response would freeze forever. With this PR, those tasks are correctly rejected with a ConnectionLost exception (we cannot queue them: as far as the SDK is concerned, it cannot know if these requests were received and processed by Kuzzle or not)
  • there was a race condition when triggering the threaded recovering process where, in rare cases, 2 reconnection attempts would run in parallel, doubling the number of opened sockets

Asynchronous tasks

  • Race conditions could occur and corrupt the requests cache, or freeze the SDK because of an unhandled exception, because of an incorrect use of lock (this keyword has no impact when multiple accesses are made to the same "locked" object within the same thread) => semaphores are now used to circumvent the problem
  • Requests tasks were incorrectly configured, making their resolution synchronous. This means that resolving tasks in the SDK event handlers (which manage network state changes) could prevent them to finish in a timely fashion (or... ever) because they would synchronously trigger awaiting code

Boyscout

  • Save our standard code style directly in the solution to share it to whomever works on the project

Fix a number of problems when handling disconnections, and with asynchronous tasks in general.

When `AbstractProtocol.AutoRecover` is set to true:

* requests sent through the network would never be resolved when the connection is lost before they receive a response. This means that clients awaiting for a response would freeze forever. With this PR, those tasks are correctly rejected with a `ConnectionLost` exception (we cannot queue them: as far as the SDK is concerned, it cannot know if these requests were received and processed by Kuzzle or not)
* there was a race condition when triggering the threaded recovering process where, in rare cases, 2 reconnection attempts would run in parallel, doubling the number of opened sockets

* Race conditions could occur and corrupt the requests cache, or freeze the SDK because of an unhandled exception, because of an incorrect use of `lock` (this keyword has no impact when multiple accesses are made to the same "locked" object within the same thread) => semaphores are now used to circumvent the problem
* Requests tasks were incorrectly configured, making their resolution synchronous. This means that resolving tasks in the SDK event handlers (which manage network state changes) could prevent them to finish in a timely fashion (or... ever) because they would synchronously trigger awaiting code

* Save our standard code style directly in the solution to share it to whomever works on the project
@codecov
Copy link

codecov bot commented Sep 29, 2020

Codecov Report

Merging #64 into 2-dev will increase coverage by 0.49%.
The diff coverage is 83.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            2-dev      #64      +/-   ##
==========================================
+ Coverage   82.02%   82.52%   +0.49%     
==========================================
  Files          34       34              
  Lines        1675     1722      +47     
  Branches      197      201       +4     
==========================================
+ Hits         1374     1421      +47     
+ Misses        277      276       -1     
- Partials       24       25       +1     
Impacted Files Coverage Δ
Kuzzle/Offline/OfflineManager.cs 70.73% <ø> (ø)
Kuzzle/Protocol/WebSocket.cs 66.44% <0.00%> (-0.23%) ⬇️
...zzle/Offline/Subscription/SubscriptionRecoverer.cs 47.54% <70.58%> (+1.38%) ⬆️
Kuzzle/Kuzzle.cs 84.30% <87.87%> (+3.05%) ⬆️
Kuzzle/Offline/Query/QueryReplayer.cs 80.53% <91.30%> (+2.66%) ⬆️
Kuzzle/EventHandler/KuzzleEventHandler.cs 74.11% <0.00%> (+3.52%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 6829a70...0f4cc6a. Read the comment docs.

@scottinet scottinet merged commit a0f7958 into 2-dev Sep 29, 2020
@scottinet scottinet deleted the v2-fix-network-recover branch September 29, 2020 08:37
@scottinet scottinet mentioned this pull request Sep 29, 2020
scottinet added a commit that referenced this pull request Sep 29, 2020
# [2.0.5](https://github.com/kuzzleio/sdk-csharp/releases/tag/2.0.5) (2020-09-29)


#### Bug fixes

- [ [#64](#64) ] Fix network recovery   ([scottinet](https://github.com/scottinet))
---
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant