Skip to content

Conversation

@scottinet
Copy link
Contributor

@scottinet scottinet commented Sep 22, 2020

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

@codecov
Copy link

codecov bot commented Sep 22, 2020

Codecov Report

Merging #62 into 1-dev will increase coverage by 0.06%.
The diff coverage is 83.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##            1-dev      #62      +/-   ##
==========================================
+ Coverage   82.60%   82.67%   +0.06%     
==========================================
  Files          34       34              
  Lines        1696     1743      +47     
  Branches      201      205       +4     
==========================================
+ Hits         1401     1441      +40     
- Misses        272      278       +6     
- Partials       23       24       +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 82.94% <87.87%> (+0.66%) ⬆️
Kuzzle/Offline/Query/QueryReplayer.cs 80.53% <91.30%> (+2.66%) ⬆️

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 7781e6f...dd114f5. Read the comment docs.

Copy link
Contributor

@Aschen Aschen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My dear c#, long time no see but looks good to me 👍

@scottinet scottinet merged commit 8b8e4a0 into 1-dev Sep 25, 2020
@scottinet scottinet deleted the fix-network-recover branch September 25, 2020 09:37
@scottinet scottinet mentioned this pull request Sep 25, 2020
scottinet added a commit that referenced this pull request Sep 25, 2020
scottinet added a commit that referenced this pull request Sep 29, 2020
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
scottinet added a commit that referenced this pull request Sep 29, 2020
# 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
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.

4 participants