Commit 6b07b4a
authored
Fix
<!--
Thanks for opening a pull request!
-->
<!-- In the case this PR will resolve an issue, please replace
${GITHUB_ISSUE_ID} below with the actual Github issue id. -->
<!-- Closes #${GITHUB_ISSUE_ID} -->
# Rationale for this change
`FsspecFileIO.get_fs` can be called by multiple threads when
`ExecutorFactory` is used (for example by `DataScan.plan_files`).
The base class of `fsspec` filesystem objects,
`fsspec.spec.AbstractFileSystem`, internally caches instances through
the `fsspec.spec._Cached` metaclass. The caching key used includes
`threading.get_ident()`, making entries thread-local:
https://github.com/fsspec/filesystem_spec/blob/f84b99f0d1f079f990db1a219b74df66ab3e7160/fsspec/spec.py#L71
The `FsspecFileIO.get_fs` LRU cache (around `FsspecFileIO._get_fs`)
breaks the thread-locality of the filesystem instances as it will return
the same instance for different threads.
One consequence of this is that for `s3fs.S3FileSystem`, HTTP connection
pooling no longer occurs per thread (as is normal with `aiobotocore`),
as the `aiobotocore` client object (containing the
`aiohttp.ClientSession`) is stored on the `s3fs.S3FileSystem`.
This change addresses this by making the `FsspecFileIO.get_fs` cache
thread-local.
## Are these changes tested?
Tested locally. Unit test included covering the caching behaviour.
## Are there any user-facing changes?
Yes - S3 HTTP connection pooling now occurs per-thread, matching the
behaviour of `aiobotocore` when it used in the recommended way with an
event loop per thread.
<!-- In the case of user-facing changes, please add the changelog label.
-->FsspecFileIO.get_fs thread safety (#2495)1 parent 513295d commit 6b07b4a
2 files changed
+50
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| 23 | + | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| |||
370 | 371 | | |
371 | 372 | | |
372 | 373 | | |
373 | | - | |
| 374 | + | |
374 | 375 | | |
375 | 376 | | |
376 | 377 | | |
| |||
416 | 417 | | |
417 | 418 | | |
418 | 419 | | |
| 420 | + | |
| 421 | + | |
| 422 | + | |
| 423 | + | |
| 424 | + | |
| 425 | + | |
| 426 | + | |
419 | 427 | | |
420 | 428 | | |
421 | 429 | | |
| |||
425 | 433 | | |
426 | 434 | | |
427 | 435 | | |
428 | | - | |
| 436 | + | |
429 | 437 | | |
430 | 438 | | |
431 | 439 | | |
432 | 440 | | |
433 | 441 | | |
434 | | - | |
| 442 | + | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
| 23 | + | |
22 | 24 | | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
27 | 30 | | |
28 | 31 | | |
29 | 32 | | |
| |||
54 | 57 | | |
55 | 58 | | |
56 | 59 | | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
57 | 96 | | |
58 | 97 | | |
59 | 98 | | |
| |||
0 commit comments