Commit b89f3a7
[Network Drive] Switch to usage of local connection cache (#3868)
## Closes #2418
Conceptual problem - `smbprotocol` has a global connection cache
[here](https://github.com/jborean93/smbprotocol/blob/master/src/smbclient/_pool.py#L33)
(see usages). Hash key is host/port:
```python
connection_key = f"{server.lower()}:{port}"
```
Library is not natively async, that means that it can cause fun stuff
when used in asynchronous/threaded environment. In our case one
connector configuration can spawn at least 2 connections for the same
server: 1 for running `get_docs` method while the sync is running and 1
for `ping` method that gets spawned every 30 seconds by default.
Things get worse if advanced filtering rules are used and several
connectors point to the same Network Drive.
What happens is:
1. `get_docs` is called and a connection is established
2. `ping` is triggered, connection is re-used from the cache
3. `ping` finishes and closes the connection. That causes the loss of
the connection by `get_docs`
4. `get_docs` sometimes can re-establish it (see [this
code](https://github.com/elastic/connectors/blob/main/app/connectors_service/connectors/sources/network_drive/datasource.py#L276)).
Sometimes it just fails
This change attempts to address it by providing connection cache that's
local to each connector instead of using a global one. This way
connector instances would not attempt to close each other's connections
if they connect to the same resource.
#### Pre-Review Checklist
- [x] this PR does NOT contain credentials of any kind, such as API keys
or username/passwords (double check `config.yml.example`)
- [x] this PR has a meaningful title
- [x] this PR links to all relevant github issues that it fixes or
partially addresses
- [x] if there is no GH issue, please create it. Each PR should have a
link to an issue
- [x] this PR has a thorough description
- [ ] Covered the changes with automated tests
- [x] Tested the changes locally
- [x] Added a label for each target release version (example: `v7.13.2`,
`v7.14.0`, `v8.0.0`)
- [ ] For bugfixes: backport safely to all minor branches still
receiving patch releases
- [ ] Considered corresponding documentation changes
- [ ] Contributed any configuration settings changes to the
configuration reference
- [ ] if you added or changed Rich Configurable Fields for a Native
Connector, you made a corresponding PR in
[Kibana](https://github.com/elastic/kibana/blob/main/packages/kbn-search-connectors/types/native_connectors.ts)
## Release Note
Fix the bug with Network Drive connector closing connections to SMB
servers prematurely.
---------
Co-authored-by: Elastic Machine <[email protected]>1 parent b6849e6 commit b89f3a7
File tree
2 files changed
+24
-6
lines changed- app/connectors_service/connectors/sources/network_drive
2 files changed
+24
-6
lines changedLines changed: 21 additions & 5 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
| 78 | + | |
78 | 79 | | |
79 | 80 | | |
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
83 | 84 | | |
84 | | - | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
85 | 92 | | |
86 | 93 | | |
87 | 94 | | |
| |||
203 | 210 | | |
204 | 211 | | |
205 | 212 | | |
| 213 | + | |
206 | 214 | | |
207 | 215 | | |
208 | 216 | | |
| |||
257 | 265 | | |
258 | 266 | | |
259 | 267 | | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
260 | 271 | | |
261 | 272 | | |
262 | 273 | | |
| |||
337 | 348 | | |
338 | 349 | | |
339 | 350 | | |
| 351 | + | |
| 352 | + | |
340 | 353 | | |
341 | | - | |
342 | | - | |
343 | 354 | | |
344 | 355 | | |
345 | 356 | | |
| |||
350 | 361 | | |
351 | 362 | | |
352 | 363 | | |
353 | | - | |
| 364 | + | |
| 365 | + | |
| 366 | + | |
| 367 | + | |
354 | 368 | | |
355 | 369 | | |
356 | 370 | | |
| |||
615 | 629 | | |
616 | 630 | | |
617 | 631 | | |
618 | | - | |
| 632 | + | |
| 633 | + | |
| 634 | + | |
619 | 635 | | |
620 | 636 | | |
621 | 637 | | |
| |||
Lines changed: 3 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
222 | 222 | | |
223 | 223 | | |
224 | 224 | | |
225 | | - | |
| 225 | + | |
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
| 231 | + | |
231 | 232 | | |
232 | 233 | | |
233 | 234 | | |
| |||
238 | 239 | | |
239 | 240 | | |
240 | 241 | | |
| 242 | + | |
241 | 243 | | |
242 | 244 | | |
243 | 245 | | |
| |||
0 commit comments