apache / apache/iceberg-python

S3FileSystem.close_session raise "attached to a different loop"

Đang mở
#2,785 1 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Python
Star
1.1k
Fork
581
Merge trung bình
1 ngày 17 giờ
Pull request đã merge (30 ngày)
78

Mô tả

### Apache Iceberg version

main branch

### Please describe the bug 🐞

# Description

This error message does not appear consistently. In my case, it is reliably triggered when performing concurrent queries on an Iceberg table, but it does not occur when querying the same table with a single process or when querying other tables.

This error occurs during the execution of weakref when the Python interpreter's cleanup process is triggered.

The error message is as follows

```
Traceback (most recent call last):
File "/home/*/python3.10/site-packages/aiobotocore/session.py", line 36, in __aexit__
await self._client.__aexit__(exc_type, exc_val, exc_tb)
File "/home/*/python3.10/site-packages/aiobotocore/client.py", line 644, in __aexit__
await self._endpoint.http_session.__aexit__(exc_type, exc_val, exc_tb)
File "/home/*/python3.10/site-packages/aiobotocore/httpsession.py", line 109, in __aexit__
await self._exit_stack.aclose()
File "/home/*/python3.10/contextlib.py", line 656, in aclose
await self.__aexit__(None, None, None)
File "/home/*/python3.10/contextlib.py", line 714, in __aexit__
raise exc_details[1]
File "/home/*/python3.10/contextlib.py", line 697, in __aexit__
cb_suppress = await cb(*exc_details)
File "/home/*/python3.10/site-packages/aiohttp/client.py", line 1483, in __aexit__
await self.close()
File "/home/*/python3.10/site-packages/aiohttp/client.py", line 1349, in close
await self._connector.close()
File "/home/*/python3.10/site-packages/aiohttp/connector.py", line 1044, in close
await super().close(abort_ssl=abort_ssl or self._ssl_shutdown_timeout == 0)
RuntimeError: Task > got Future > attached to a different loop
ERROR:asyncio:Task exception was never retrieved
future: exception=RuntimeError("Task > got Future > attached to a different loop")>
```

# Reason

This bug maybe be caused by #2495 . I revert #2495 and it can work normally.

In #2495 :

In FsspecFileIO, the S3FileSystem instance—which carries an event loop—is stored in threading.local(). This very likely (though I currently lack concrete evidence; it may be caused in combination with other logic) leads to the error during garbage collection at program shutdown.

### Willingness to contribute

- [ ] I can contribute a fix for this bug independently
- [x] I would be willing to contribute a fix for this bug with guidance from the Iceberg community
- [ ] I cannot contribute a fix for this bug at this time

Hướng dẫn đóng góp

Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này

Hướng nghiên cứu

Bắt đầu bằng cách lần theo vòng đời của threading.local() S3FileSystem trong FsspecFileIO và quá trình dọn dẹp weakref của S3FileSystem.close_session được mô tả ở đây. Tái hiện lỗi bằng các truy vấn đồng thời trên một bảng Iceberg, sau đó xác minh rằng việc trình thông dịch tắt không còn gây ra lỗi attached-to-a-different-loop.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
aws, python
Lĩnh vực
backend, cloud
Loại issue
Lỗi
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Ít trao đổi
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
48/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.