Commit 8b8e4a0
authored
Fix network recovering (#62)
# 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 project1 parent 7781e6f commit 8b8e4a0
File tree
7 files changed
+142
-75
lines changed- Kuzzle.Tests/Offline/Query
- Kuzzle
- Offline
- Query
- Subscription
- Protocol
7 files changed
+142
-75
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
147 | 147 | | |
148 | 148 | | |
149 | 149 | | |
150 | | - | |
151 | | - | |
152 | | - | |
153 | | - | |
154 | | - | |
155 | | - | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
156 | 156 | | |
157 | 157 | | |
158 | 158 | | |
| |||
168 | 168 | | |
169 | 169 | | |
170 | 170 | | |
171 | | - | |
172 | | - | |
173 | | - | |
174 | | - | |
175 | | - | |
176 | | - | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
177 | 177 | | |
178 | 178 | | |
179 | 179 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
| 72 | + | |
71 | 73 | | |
72 | 74 | | |
73 | 75 | | |
| |||
219 | 221 | | |
220 | 222 | | |
221 | 223 | | |
222 | | - | |
223 | 224 | | |
224 | 225 | | |
225 | 226 | | |
| |||
228 | 229 | | |
229 | 230 | | |
230 | 231 | | |
231 | | - | |
232 | | - | |
233 | | - | |
234 | | - | |
235 | | - | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
236 | 236 | | |
237 | | - | |
238 | | - | |
239 | | - | |
240 | | - | |
241 | | - | |
| 237 | + | |
242 | 238 | | |
243 | | - | |
244 | | - | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
245 | 242 | | |
246 | 243 | | |
247 | | - | |
| 244 | + | |
| 245 | + | |
| 246 | + | |
| 247 | + | |
| 248 | + | |
248 | 249 | | |
249 | | - | |
250 | | - | |
| 250 | + | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
251 | 256 | | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
252 | 260 | | |
253 | 261 | | |
254 | 262 | | |
255 | | - | |
256 | | - | |
257 | | - | |
| 263 | + | |
| 264 | + | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
258 | 272 | | |
259 | 273 | | |
260 | 274 | | |
261 | 275 | | |
262 | 276 | | |
263 | 277 | | |
| 278 | + | |
| 279 | + | |
| 280 | + | |
264 | 281 | | |
265 | 282 | | |
266 | 283 | | |
| |||
376 | 393 | | |
377 | 394 | | |
378 | 395 | | |
| 396 | + | |
| 397 | + | |
| 398 | + | |
| 399 | + | |
| 400 | + | |
379 | 401 | | |
380 | 402 | | |
381 | | - | |
382 | | - | |
383 | 403 | | |
384 | | - | |
385 | | - | |
386 | | - | |
| 404 | + | |
| 405 | + | |
387 | 406 | | |
388 | 407 | | |
389 | 408 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
11 | 11 | | |
12 | 12 | | |
13 | 13 | | |
14 | | - | |
15 | 14 | | |
16 | 15 | | |
17 | 16 | | |
| |||
46 | 45 | | |
47 | 46 | | |
48 | 47 | | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
230 | 229 | | |
231 | 230 | | |
232 | 231 | | |
| |||
235 | 234 | | |
236 | 235 | | |
237 | 236 | | |
| 237 | + | |
238 | 238 | | |
239 | 239 | | |
240 | 240 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
| 6 | + | |
6 | 7 | | |
7 | 8 | | |
8 | 9 | | |
| |||
73 | 74 | | |
74 | 75 | | |
75 | 76 | | |
| 77 | + | |
76 | 78 | | |
77 | 79 | | |
78 | 80 | | |
| |||
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
106 | | - | |
| 108 | + | |
| 109 | + | |
107 | 110 | | |
108 | 111 | | |
109 | 112 | | |
110 | 113 | | |
111 | 114 | | |
112 | | - | |
| 115 | + | |
| 116 | + | |
113 | 117 | | |
114 | 118 | | |
115 | 119 | | |
116 | 120 | | |
117 | 121 | | |
118 | | - | |
119 | | - | |
120 | | - | |
121 | | - | |
122 | | - | |
123 | | - | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
124 | 129 | | |
125 | 130 | | |
126 | 131 | | |
127 | 132 | | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
128 | 137 | | |
129 | 138 | | |
130 | 139 | | |
| |||
139 | 148 | | |
140 | 149 | | |
141 | 150 | | |
142 | | - | |
| 151 | + | |
| 152 | + | |
143 | 153 | | |
144 | 154 | | |
145 | 155 | | |
| |||
149 | 159 | | |
150 | 160 | | |
151 | 161 | | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
152 | 165 | | |
153 | 166 | | |
154 | 167 | | |
| |||
163 | 176 | | |
164 | 177 | | |
165 | 178 | | |
166 | | - | |
| 179 | + | |
| 180 | + | |
167 | 181 | | |
168 | 182 | | |
169 | | - | |
| 183 | + | |
| 184 | + | |
| 185 | + | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
170 | 192 | | |
171 | 193 | | |
| 194 | + | |
172 | 195 | | |
| 196 | + | |
173 | 197 | | |
174 | 198 | | |
175 | 199 | | |
176 | 200 | | |
177 | 201 | | |
178 | 202 | | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
179 | 206 | | |
180 | 207 | | |
181 | 208 | | |
182 | 209 | | |
183 | 210 | | |
184 | 211 | | |
185 | 212 | | |
186 | | - | |
| 213 | + | |
| 214 | + | |
187 | 215 | | |
188 | 216 | | |
189 | 217 | | |
| |||
196 | 224 | | |
197 | 225 | | |
198 | 226 | | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
199 | 230 | | |
200 | 231 | | |
201 | 232 | | |
202 | 233 | | |
203 | 234 | | |
204 | 235 | | |
205 | 236 | | |
206 | | - | |
207 | | - | |
208 | | - | |
209 | | - | |
210 | | - | |
211 | | - | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
| 240 | + | |
| 241 | + | |
| 242 | + | |
212 | 243 | | |
213 | 244 | | |
214 | 245 | | |
| |||
255 | 286 | | |
256 | 287 | | |
257 | 288 | | |
258 | | - | |
| 289 | + | |
| 290 | + | |
259 | 291 | | |
260 | 292 | | |
261 | 293 | | |
| |||
267 | 299 | | |
268 | 300 | | |
269 | 301 | | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
270 | 305 | | |
271 | 306 | | |
272 | 307 | | |
| |||
0 commit comments