Skip to content

Commit

Permalink
Merge pull request #4 from remerge/reset-lock-on-fork-process
Browse files Browse the repository at this point in the history
  • Loading branch information
rshkarin committed Sep 4, 2024
2 parents 9c3f611 + d8d6512 commit eb9ccce
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 5 deletions.
10 changes: 10 additions & 0 deletions docs/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ Changelog
Note: in some releases, there are no changes, because we always guarantee relasing in step
with fsspec.

2024.6.1
--------

no changes

2024.6.0
--------

* Add seek(0) to request data to prevent issues on retries (#624)

2024.5.0
--------

Expand Down
2 changes: 1 addition & 1 deletion environment_gcsfs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ dependencies:
- fusepy<3
- google-api-core
- google-api-python-client
- google-auth
- google-auth>=1.2, <2.33
- google-auth-oauthlib
- google-cloud-core
- google-cloud-storage
Expand Down
6 changes: 6 additions & 0 deletions gcsfs/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@
from .inventory_report import InventoryReport
from .retry import errs, retry_request, validate_response

os.register_at_fork(
after_in_child=asyn.reset_lock,
)

logger = logging.getLogger("gcsfs")


Expand Down Expand Up @@ -421,6 +425,8 @@ async def _request(
self, method, path, *args, headers=None, json=None, data=None, **kwargs
):
await self._set_session()
if hasattr(data, "seek"):
data.seek(0)
async with self.session.request(
method=method,
url=self._format_path(path, args),
Expand Down
8 changes: 6 additions & 2 deletions gcsfs/retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,11 @@ def validate_response(status, content, path, args=None):
content = content.decode()
try:
error = json.loads(content)["error"]
msg = error["message"]
# Sometimes the error message is a string.
if isinstance(error, str):
msg = error
else:
msg = error["message"]
except json.decoder.JSONDecodeError:
msg = content

Expand All @@ -109,7 +113,7 @@ def validate_response(status, content, path, args=None):
raise requests.exceptions.ProxyError()
elif "invalid" in str(msg):
raise ValueError(f"Bad Request: {path}\n{msg}")
elif error:
elif error and not isinstance(error, str):
raise HttpError(error)
elif status:
raise HttpError({"code": status, "message": msg}) # text-like
Expand Down
9 changes: 9 additions & 0 deletions gcsfs/tests/test_retry.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,15 @@ def test_validate_response():
validate_response(502, b"", "/path")


def test_validate_response_error_is_string():
# HttpError with JSON body
j = '{"error": "Too Many Requests"}'
with pytest.raises(HttpError) as e:
validate_response(429, j, "/path")
assert e.value.code == 429
assert e.value.message == "Too Many Requests, 429"


@pytest.mark.parametrize(
["file_path", "validate_get_error", "validate_list_error", "expected_error"],
[
Expand Down
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
aiohttp!=4.0.0a0, !=4.0.0a1
decorator>4.1.2
fsspec==2024.5.0
google-auth>=1.2
fsspec==2024.6.1
google-auth>=1.2, <2.33
google-auth-oauthlib
google-cloud-storage
requests

0 comments on commit eb9ccce

Please sign in to comment.